Dowemo
0 0 0 0

First commit:


It has to be 18. I've ignored a problem; if you enter 1000.

First output 1000 - 0001 = 999 is a problem with no formatting considerations

So it's the format of cout and printf. I found that the point of points in the grade 20 problem is automatically fixed zero, which is very common.

It'll often meet the output format of this % 0nd, and it's necessary to pay attention to it.


Second: with % 0nd output, full score ac




The code is enclosed:


#include <iostream>
#include<algorithm>
using namespace std;
int main()
{
 int n;
 cin>>n;
 while (1)
 {
 int qian= n/1000;
 int bai= n % 1000/100;
 int shi= n % 100/10 ;
 int ge= n % 10;
 if (qian==bai&&bai==shi&&shi==ge)
 {
 cout<<n<<" -"<<n<<" ="<<"0000"<<endl;
 break;
 }
 int c[4];
 c[0]=qian;
 c[1]=bai;
 c[2]=shi;
 c[3]=ge;
 sort(c,c+4);
 cout<<c[3]<<c[2]<<c[1]<<c[0];
 cout<<" -";
 cout<<c[0]<<c[1]<<c[2]<<c[3];
 cout<<" =";
 int a=c[3]*1000+c[2]*100+c[1]*10+c[0];
 int b=c[0]*1000+c[1]*100+c[2]*10+c[3];
 n=a-b;
 printf("%04dn",n);//就是这里需要特别注意用%0nd的格式输出 
 if (n==6174)
 {
 break;
 }
 }
 return 0;
}





Copyright © 2011 Dowemo All rights reserved.    Creative Commons   AboutUs