- 相关推荐
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、求组合数: 求 n 个数(1....n)中 k 个数的组合....
如: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) //当栈底元素弹出&&为可能取的最小值,循环退出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.unjs.com/【c面试题目(2)】相关文章:
海信面试英语题目07-05
hr面试问题题目及面试技巧08-09
师德师风的征文题目(2)08-14
android面试题目09-08
星巴克面试英语题目08-06
文员面试题目10-14
面试必要备5个C10-01
c1和c2驾照考试的区别08-02
小升初名校面试题目10-11
郑州小升初面试题目06-05