Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
暴水!!!附代码!!!#include<stdio.h> #include<string.h> #include<stdlib.h> int same(char s[]) { int i=0; for(i=1;i<strlen(s);i++) if(s[i]!=s[0]) return 1; return 0; } int cmp1(const void *a,const void *b) { return (*(char*)a-*(char*)b); } int cmp2(const void *b,const void *a) { return (*(char*)a-*(char*)b); } int main() { int n,g,h,j,i,k; char d[333]; while(gets(d),d[0]!='-') { h=0; printf("N=%s:\n",d); g=strlen(d); if(g!=4||same(d)==0) { printf("No!!\n"); } else { while(1) { qsort(d,strlen(d),sizeof(d[0]),cmp2); //printf("%s\n",d); char temp[44]; strcpy(temp,d); int n,m; m=atoi(temp); qsort(d,strlen(d),sizeof(d[0]),cmp1); n=atoi(d); //printf("%s\n",d); /*if(n-m==0||n-m==6174) break;*/ for(i=0;i<strlen(temp);i++) { if(temp[i]!='0') { break; } } for(;i<strlen(temp);i++) printf("%c",temp[i]); printf("-"); for(i=0;i<strlen(d);i++) { if(d[i]!='0') { break; } } for(;i<strlen(d);i++) printf("%c",d[i]); printf("="); printf("%d\n",m-n); itoa(m-n,d,10); h++; if(m-n==0||m-n==6174) break; } } if(h!=0) printf("Ok!! %d times\n",h); } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator