- 相關(guān)推薦
c面試題目(2)
{
stra[i++]=num%10+48;
num=num/10;
}
stra[i] = '\0';
for( j=0; j < i; j++)
{
strb[j] = stra[i-j-1];
}
strb[j] = '\0';
cout<
}
int main()
{
int num;
cin>>num;
itochar(num);
return 0;
}
3、求組合數(shù): 求 n 個數(shù)(1....n)中 k 個數(shù)的組合....
如:combination(5,3)
要求輸出:543,542,541,532,531,521,432,431,421,321,
#include
int pop(int *);
int push(int );
void combination(int ,int );
int stack[3]={0};
top=-1;
int main()
{
int n,m;
printf("Input two numbers:\n");
while( (2!=scanf("%d%*c%d",&n,&m)) )
{
fflush(stdin);
printf("Input error! Again:\n");
}
combination(n,m);
printf("\n");
}
void combination(int m,int n)
{
int temp=m;
push(temp);
while(1)
{
if(1==temp)
{
if(pop(&temp)&&stack[0]==n) //當(dāng)棧底元素彈出&&為可能取的最小值,循環(huán)退出break;
}
else if( push(--temp))
{
printf("%d%d%d ",stack[0],stack[1],stack[2]);//§¨ì¤@?
pop(&temp);
}
}
}
int push(int i)
{
stack[++top]=i;
if(top<2)
return 0;
else
return 1;
}
int pop(int *i)
{
*i=stack[top--];
if(top>=0)
return 0;
else
return 1;
http://www.zwdianwu.cn/【c面試題目(2)】相關(guān)文章:
海信面試英語題目07-05
hr面試問題題目及面試技巧08-09
師德師風(fēng)的征文題目(2)08-14
android面試題目09-08
星巴克面試英語題目08-06
文員面試題目10-14
面試必要備5個C10-01
c1和c2駕照考試的區(qū)別08-02
小升初名校面試題目10-11
鄭州小升初面試題目06-05