Key:
- 输入格式
- 输出格式
- 进入循环的条件
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <set>
using namespace std;
bool cmp(char a,char b){
return a>b;
}
int main(){
string s,min,max;
cin>>s;
s.insert(0,4-s.size(),'0');//key sentence
do{
sort(s.begin(),s.end(),cmp);
max=s;
sort(s.begin(),s.end());
min=s;
s=to_string(stoi(max)-stoi(min));
s.insert(0,4-s.size(),'0');//key sentence
cout<<max<<" - "<<min<<" = "<<s<<endl;
}while(s!="0000"&&s!="6174");//do-while is key
return 0;
}