这题目最坑了,我做的A题最坑的一道
1,首先输入数据不一定是四位的,泪奔,输入1,222,222,试一试
2,在运行过程中需要判定结果是否为0,需要跳出
#include<stdio.h> #include<string.h> #include<algorithm> using namespace std; void get(char * data,int & max,int &min) { sort(data,data+4); min=(data[0]-'0')*1000+(data[1]-'0')*100+(data[2]-'0')*10+(data[3]-'0'); max=(data[3]-'0')*1000+(data[2]-'0')*100+(data[1]-'0')*10+(data[0]-'0'); } void int2char(char * p,int num) { int temp; int j=3; while(j>=0) { temp=num%10; p[j]=temp+'0'; num=num/10; j--; } } int main() { char data[5]; int da; int min,max,result; memset(data,0,sizeof(char)*5); while(scanf("%d",&da)!=EOF) { sprintf(data,"%04d",da); get(data,max,min); memset(data,0,sizeof(char)*5); result=max-min; //printf("%d %d ",min,max); printf("%04d - %04d = %04d ",max,min,result); if(result==0) continue; while(true) { if(result==6174||result==0) break; char temp[5]; temp[4]='