解题思路:
迭代,调用一次次数加一
注意事项:
t必须为static,保证累积效果。
参考代码:
#include<iostream> #include<string> #include<algorithm> using namespace std; static int t=0; int f(int m){ if(m==6174)return t; t++; int a[4],b[4],n; if(m>0)a[0]=m%10; if(m>10)a[1]=(m-a[0])/10%10; if(m>100)a[2]=(m-a[0]-10*a[1])/100%10; if(m>1000)a[3]=m/1000; sort(a,a+4); n=a[3]*1000+a[2]*100+a[1]*10+a[0]; m=a[0]*1000+a[1]*100+a[2]*10+a[3]; m=n-m; f(m); } int main() { int m,p; cin>>m; p=f(m); cout<<p; return 0; }
0.0分
0 人评分
2003年秋浙江省计算机等级考试二级C 编程题(1) (C语言代码)浏览:683 |
C语言训练-素数问题 (C语言代码)浏览:1660 |
数组输出 (C语言代码)错误???浏览:565 |
WU-蓝桥杯算法提高VIP-交换Easy (C++代码)浏览:1118 |
C语言训练-自由落体问题 (C语言代码)浏览:615 |
C语言程序设计教程(第三版)课后习题10.3 (C语言代码)浏览:1918 |
2003年秋浙江省计算机等级考试二级C 编程题(1) (C语言代码)浏览:518 |
复数求和 (C语言代码)浏览:926 |
陶陶摘苹果2 (C语言代码)浏览:601 |
盐水的故事 (C语言代码)浏览:1528 |