표제:
해결책:
直接模拟即可,主要难点在于字符串和数字之间的相互转换.
数字转字符串to_sting()
字符串转数字itos()
암호:
#include<bits/stdc++.h>
using namespace std;
const int maxm=2e6+5;
bool cmp(char a,char b){
return a>b;
}
bool cmp2(char a,char b){
return a<b;
}
void solve(){
int n,k;cin>>n>>k ;
int now=n;
for(int i=1;i<=k;i++){
string s=to_string(now);
string ss=to_string(now);
sort(s.begin(),s.end(),cmp);
sort(ss.begin(),ss.end(),cmp2);
int x=stoi(s);
int y=stoi(ss);
now=x-y;
}
cout<<now<<endl;
}
signed main(){
solve();
return 0;
}