输出:
最终被留下的小朋友的序号
说明:
如“要被练习的数字”是5,则每次数到5的同学要退出该游戏 1. #include
4. int N,n,i,s=0,a;
5. scanf(\,&N,&n); 6. for(i=2;i<=N;i++) 7. s=(s+n)%i; 8. a=s+1;
9. printf(\,a); 10. }
29 组成最大数
成绩: 10 / 折扣: 0.8
任意输入一个自然数,输出该自然数的各位数字组成的最大数。例如,输入 1593 ,则输出为 9531 。 输入: 自然数 n
输出: 各位数字组成的最大数 1. #include
5. char a[100000],c; 6. int i,j,k;
7. scanf(\,&a); 8. i=strlen(a);
9. for(j=0;j
30 删除重复字符
成绩: 5 / 折扣: 0.8
背景:
输入一个长度不超过 100 的字符串,删除串中的重复字符。
输入:
输入要检查的字符串,长度不超过100个字符。例如:abacaeedabcdcd。
输出:
删除重复字符后的字符串。例如:abced。
1. #include
3. #include
5. int alread_saved(char lastchar, char newstr[], int j) 6. 7. { 8.
9. int i=0; 10. 11. while(i 18. 19. } 20. 21. return 0; 22. 23. } 24. 25. void main() 26. 27. { 28. char str[100]; char newstr[100]; int n,i,j; 29. 30. i=0; 31. 32. j=0; 33. 34. gets(str); 35. 36. while(str[i]!='\\0') 37. 38. { 39. 40. if(!alread_saved(str[i],newstr,j)) 41. { newstr[j]=str[i]; j++; 42. 43. } 44. i++; 45. 46. } 47. 48. newstr[j]='\\0'; 49. 50. puts(newstr); 51. 52. } 31 合并字符串 成绩: 10 / 折扣: 0.8 输入两个已经按从小到大顺序排列好的字符串,编写一个合并两个字符串的函数,使合并后的字符串,仍然是从小到 大排列。 输入: 两个已经排好顺序(升序)的两个字符串 输出: 一个合并在一起的有序(升序)的字符串 要求: 设计一个效率尽量高的算法,对每个字符串只扫描一遍就可以了。 如果采用先进行串连接,然后再进行排序的算法,则效率太低了。 1. #include 3. #include 5. void MergeList(char str1[],char str2[],char str3[]); 6. 7. void main() 8. 9. { 10. char str1[100]; char str2[100]; char str3[100]; gets(str1); gets(str2); 11. 12. MergeList(str1,str2,str3); 13. 14. printf(\,str3); 15. 16. } 17. 18. void MergeList(char str1[],char str2[],char str3[]) 19. 20. { 21. 22. int i,j,k; 23. 24. i=0;j=0;k=0; 25. int lengthOfStr1,lengthOfStr2; lengthOfStr1=strlen(str1); lengthOfStr2=strlen(str2); 26. while(i 31. } 32. while(i while(j 32 串的减法 成绩: 10 / 折扣: 0.8 输入字符串s和t(串长不超过80个字符),将在字符串s中出现,但未在字符串t中出现的字符组成一个新的字符串放在u中,u中字符按原字符串中字符顺序排列,不去掉重复字符,输出u。 例如:当s=\,t=\时,u=\。 输入: 第一行为串s 第二行为串t 输出: 串u 1. #include 5. char a[80]; 6. char b[80]; 7. gets(a); 8. gets(b); 9. 10. int l=strlen(a); 11. 12. for(int i=0;b[i]!='\\0';i++) 13. { 14. for(int j=0;j