232 条题解
-
5Corner LV 8 @ 2009-08-22 11:24:24
温馨提示:
你想拿高分吗?为什么还是0分?为什么我还是只有10分!是我的智商有问题,还是我的程序有问题?
我们向您提供几个要点。如果您现在就拿起电话,我们还将免费送你一套正确的代码。赶快行动吧!第一:请检查您的程序有没有“补零”,一般来说有这一点,你就可以得90分了。
第二:如果您还是90分,而且想不到的话。
请看:54321 的答案是这个。
82962 75933 63954 61974
那么你的程序输入82962,答案是多少?
别再往下看先。。。如果你测试了很久,还是想不通,那么再看33.你还是90分,过不了吗?
那好,请看。如果输入82962,那么82962并没有在您的答案中排头吧?
是不是排在尾巴?
而按照题目意思,
答案应该是以82962开头的!哈哈~~~
我第一次全部WA
第二次还是WA第三次90
第四次0
第五次100奇怪吧!
var
a:array[1..500000] of int64;
i,j:longint;
k,m,n,x,y,check,an,num,gd,divs:int64;
procedure get;
var
b:array[1..11] of integer;
i,j:longint;
k,sum:int64;
begin
fillchar(b,sizeof(b),0);
sum:=0;
while x>0 do
begin
inc(sum);
b[sum]:=x mod 10;
x:=x div 10;
end;
for i:=1 to sum do
for j:=i to sum do
if b[i]0 do begin inc(num); gd:=gd div 10; end;
dec(num);
divs:=1;
for i:=1 to num-1 do
divs:=divs*10;
check:=0;
while check=0 do
begin
get;
for i:=1 to an do
if a[i]=x then
begin
for j:=i to an do
write(a[j],' ');
check:=1;
end;if check=0 then begin inc(an); a[an]:=x; end;
while (x div divs = 0) and (x>0) do x:=x*10;
end;
writeln;
end;
end.赶快拿起电话订购吧!!~~~~~
-
32017-05-07 12:56:39@
/* 一道很纯粹的模拟题惹~ 嗯其实很好写的呀~只要注意一些细节问题 循环节的问题的话应该碰到过很多了 只需要用个set维护是否出现(或者手写个hash也不麻烦) 然后不断进行操作产生新的数 直到产生了一个已经产生过的数结束~ 那么我们很容易发现 这个数用直接数字肯定是不方便的 所以窝们用string类就好啦~ 然后string字母排个序 组合出最大值最小值 然后得到一个新的string 至于输出答案的问题窝们可以用一个vector记录一下循环中的各个字符串 然后碰到已经出现的字符串停止之后 就再到向量中去找到这个字符串上一次出现的位置 就一直输出到最后就好啦~ 花了快半小时才写好+调试好 然后发现全WA只有10分 害怕啊 后来发现数据有一个地方写成了int没开longlong Orz果真窝好弱 */ #include <iostream> #include <cstdio> #include <algorithm> #include <cstring> #include <vector> #include <set> using namespace std; vector<string> ans; set<string> s; string now; int l; void init() { ans.clear(); s.clear(); } long long getmax(string& c) { long long ans=0; for(int i=l-1;i>=0;i--) ans=(ans*10)+c[i]-'0'; return ans; } long long getmin(string& c) { long long ans=0; for(int i=0;i<l;i++) ans=(ans*10)+c[i]-'0'; return ans; } string tostring(long long x) { char a[1000]; int l=0; while(x) { a[l++]=x%10+'0'; x/=10; } a[l]='\0'; string c(a); reverse(c.begin(),c.end()); return c; } int main() { while(cin>>now) { init(); while(!s.count(now)) { s.insert(now); ans.push_back(now); sort(now.begin(),now.end()); l=now.length(); long long a=getmax(now); long long b=getmin(now); now=tostring(a-b); } ans.push_back(now); int k=0; while(ans[k]!=now) k++; cout<<ans[k]<<" "; while(ans[++k]!=now) cout<<ans[k]<<" "; cout<<endl; } return 0; }
-
12020-10-13 19:50:44@
#include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <algorithm> #include <vector> #include <deque> using namespace std; namespace dts { typedef long long ll; const ll key=10000007; ll n,ha[key]; int cmp_min(ll a,ll b) { return a<b; } int cmp_max(ll a,ll b) { return a>b; } ll number(ll num,ll task) { ll ans=0,size=0,a[20]; for (ll i=num;i;i/=10,size++) a[size]=i%10; if (task==-1) sort(&a[0],&a[size],cmp_min); else if (task==1) sort(&a[0],&a[size],cmp_max); for (ll i=0;i<size;i++) ans*=10,ans+=a[i]; return ans; } ll hash(ll num) { ll ans; for (ans=num%key;ha[ans]!=-1;ans++,ans%=key) if (ha[ans]==num) return ans; return ans; } void main() { while (~scanf("%lld",&n)) { memset(ha,-1,sizeof(ha)); ha[hash(n)]=n; ll now=n,ans; while (1) { ll next=number(now,1)-number(now,-1); ll has=hash(next); if (ha[has]==next) { printf("%lld ",ans=next); break; } ha[has]=next; now=next; } for (ll i=number(ans,1)-number(ans,-1);i!=ans;i=number(i,1)-number(i,-1)) printf("%lld ",i); printf("\n"); } } } int main() { dts::main(); }
-
12017-07-14 18:33:14@
哇,神他妈竟然第一次的输入也要insert进去,不然第10个点WA
#include<iostream> #include<set> #include<vector> #include<algorithm> using namespace std; set<string>dataNum; vector<unsigned long long>record; void init(){ dataNum.clear(); record.clear(); } unsigned long long sortString(string& data){ sort(data.begin(),data.end()); unsigned long long min=atoll(data.c_str()); reverse(data.begin(),data.end()); unsigned long long max=atoll(data.c_str()); return max-min; } unsigned long long get10(int num){ unsigned long long ans=1; for(int i=0;i<num;i++){ ans*=10; } return ans; } void check(string& data){ unsigned long long index=sortString(data); string value=to_string(index); if(value.size()<data.size()){ index*=get10(data.size()-value.size()); } value=to_string(index); if(dataNum.find(value)==dataNum.end()){ dataNum.insert(value); record.push_back(index); check(value); } else{ int i=0; for(i=0;i<record.size();i++){ if(record[i]==index){ break; } } for(int j=i;j<record.size();j++){ cout<<record[j]<<' '; } cout<<endl; return; } } int main(void){ string num; while(cin>>num){ init(); record.push_back(atoll(num.c_str())); dataNum.insert(num); check(num); } }
-
02022-05-05 19:21:34@
#include <iostream> #include <cstdio> #include <algorithm> #include <cstring> #include <vector> #include <set> using namespace std; vector<string> ans; set<string> s; string now; int l; void init() { ans.clear(); s.clear(); } long long getmax(string& c) { long long ans=0; for(int i=l-1;i>=0;i--) ans=(ans*10)+c[i]-'0'; return ans; } long long getmin(string& c) { long long ans=0; for(int i=0;i<l;i++) ans=(ans*10)+c[i]-'0'; return ans; } string tostring(long long x) { char a[1000]; int l=0; while(x) { a[l++]=x%10+'0'; x/=10; } a[l]='\0'; string c(a); reverse(c.begin(),c.end()); return c; } int main() { while(cin>>now) { init(); while(!s.count(now)) { s.insert(now); ans.push_back(now); sort(now.begin(),now.end()); l=now.length(); long long a=getmax(now); long long b=getmin(now); now=tostring(a-b); } ans.push_back(now); int k=0; while(ans[k]!=now) k++; cout<<ans[k]<<" "; while(ans[++k]!=now) cout<<ans[k]<<" "; cout<<endl; } return 0; }
-
02018-09-15 15:49:53@
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <algorithm> #include <math.h> bool cmp1( int a, int b) { return a > b; } unsigned long long int calculate(unsigned long long int num) { unsigned long long int min, max, i, cha; char s[100]; for (i = 0; num > 0; i++) { s[i] = num % 10 + '0'; num /= 10; } std::sort(s, s + (i > 4 ? i : 4)); min = atoll(s); std::sort(s, s + (i > 4 ? i : 4), cmp1); max = atoll(s); cha = max - min; if (cha == 0) return min; if (cha < 10) cha *= 1000; else if (cha < 100) cha *= 100; else if (cha < 1000) cha *= 10; return cha; } int check(unsigned long long int *p, int n) { int i, j; for (i = 0; i < n; i++) { if (*(p + n) == *(p + i)) { for (j = i; j < n; j++) { printf("%lld ", *(p + j)); } return 1; } } return 0; } int main(void) { int i; unsigned long long int num, loop[100]; while (scanf("%lld", &num) != EOF) { loop[0] = num; for (i = 0; i < 99; i++) { loop[i + 1] = calculate(loop[i]); if (check(loop, i + 1)) { printf("\n"); break; } } } return 0; }
-
02017-07-14 10:13:17@
弗洛伊德判圈算法。
-
02017-06-03 20:29:57@
万恶的long long...
害我两次wa...
#include<bits/stdc++.h>
using namespace std;
long long a[30],s[2000],ts=1,n,v=-1;
bool cmp_m(int a,int b){
return a>b;
}
bool cmp_s(int a,int b){
return a<b;
}
bool check(){
for(long long i=ts-2;i>=0;i--){
if(s[i]==s[ts-1]){
v=i;
return 1;
}
}
return 0;
}
int main()
{
int t=0;
while(cin>>n){
ts=1;
v=-1;
memset(s,0,sizeof(s));
memset(a,0,sizeof(a));
s[0]=n;
do{
n=s[ts-1];
t=0;
long long t1=0,t2=0;
do{
a[t++]=n%10;
n/=10;
}while(n>0);
sort(a,a+t,cmp_s);
for(int i=0;i<t;i++){
t1*=10;
t1+=a[i];
}
sort(a,a+t,cmp_m);
for(int i=0;i<t;i++){
t2*=10;
t2+=a[i];}
s[ts++]=t2-t1;
}while(!check());
for(int j=v;j<ts-1;j++)cout<<s[j]<<" ";
cout<<endl;
}
return 0;
} -
02016-10-17 17:27:34@
讲讲思路吧~~这种题目如果发代码每个人的风格都不一样可读性不高呀~
一道很纯粹的模拟题惹~
嗯其实很好写的呀~只要注意一些细节问题
循环节的问题的话应该碰到过很多了
只需要用个set维护是否出现(或者手写个hash也不麻烦)
然后不断进行操作产生新的数
直到产生了一个已经产生过的数结束~
那么我们很容易发现 这个数用直接数字肯定是不方便的
所以窝们用string类就好啦~
然后string字母排个序 组合出最大值最小值
然后得到一个新的string
至于输出答案的问题窝们可以用一个vector记录一下循环中的各个字符串
然后碰到已经出现的字符串停止之后
就再到向量中去找到这个字符串上一次出现的位置
就一直输出到最后就好啦~
花了快半小时才写好+调试好 然后发现全WA只有10分
害怕啊 后来发现数据有一个地方写成了int没开longlong
Orz果真窝好弱QWQ
NOIP要被虐啦~ -
02016-10-07 14:41:21@
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <sstream>
#include <set>
#include <vector>
#include <algorithm>
using namespace std;
const int MAXN = 1000 + 5;
long long n;
int main()
{
stringstream ss; ss.str("");ss.clear();
set<string> Set;
ios::sync_with_stdio(0);
string s;
vector<string> ans;
while (cin>>s) {
Set.clear(); ans.clear();
while (!Set.count(s)) {
long long Lnum=0,Gnum=0,td=0;
Set.insert(s);
ans.push_back(s);
string temp(s);sort(temp.begin(),temp.end());//greater
ss<<temp; ss>>Lnum; ss.str(""); ss.clear();reverse(temp.begin(),temp.end());
while(temp.length()<4)
temp+="0";
ss<<temp; ss>>Gnum; ss.str(""); ss.clear();td=Gnum-Lnum;
ss<<td; ss>>s; ss.str("");ss.clear();}
bool yes=false;
for (unsigned int i=0;i<ans.size();i++) {
if (ans[i]==s) yes=true;
if (yes) cout<<ans[i]<<' ';
}
cout<<endl;
}
return 0;
} -
02016-08-13 16:14:57@
#include <cstdio> #include <iostream> #include <algorithm> #include <cstring> using namespace std; typedef unsigned long long LL; LL d[16],v[201],n,tmp; int len,s; bool comp(LL a,LL b){ return a>b; } void cut(LL k,LL d[16]){ for (int i=1;i<=len;i++){ d[i]=k%10; k/=10; } } bool find(LL n,int s){ int i=0; while (i<s && v[i]!=n) i++; if (i<s) return true; else return false; } LL getmax(LL d[16]){ LL temp=0; for (int i=1;i<=len;i++) temp=temp*10+d[i]; return temp; } LL getmin(LL d[16]){ LL temp=0; for (int i=len;i>=1;i--) temp=temp*10+d[i]; return temp; } int main(){ freopen("string.in","r",stdin); freopen("string.out","w",stdout); while (scanf("%I64d",&n)!=EOF) { memset(v,0,sizeof(v)); memset(d,0,sizeof(d)); len=0; tmp=n; while (tmp!=0){ tmp/=10;len++; } s=0;v[0]=n; do{ cut(v[s],d); sort(d+1,d+len+1,comp); s++; v[s]=getmax(d)-getmin(d); }while(!find(v[s],s)); int i=0; while (v[s]!=v[i]) i++; for (int j=i;j<=s-1;j++) printf("%I64d ",v[j]); printf("\n"); } }
第一次,开int,对一个点;
第二次,开unsigned long long,AC,15ms。
这差距我接受不了 -
02016-05-19 16:58:49@
-
02015-09-27 09:27:28@
#include "string.h"
#include "stdlib.h"
#include "stdio.h"#define Int64 (long long)
const int Min = 0;
const int Max = 1;int64 GetVal(int64 val, int type)
{
char chBuf[40];
itoa(val, chBuf, 10);
int iLen = strlen(chBuf);
for (int i = iLen-1; i >= 0; i--)
{
for (int j = i-1; j >= 0; j--)
{
__int64 tmp = 0;
if (((type == Min) && (chBuf[i] < chBuf[j])) ||
((type == Max) && (chBuf[i] > chBuf[j])))
{
tmp = chBuf[i];
chBuf[i] = chBuf[j];
chBuf[j] = tmp;
}
}
}
return atoi(chBuf);
}int64 g_iOutput[1000];
int g_iNum;
int g_iIdx;
bool Check(int64 iVal)
{
for (int i = 0; i < g_iNum; i++)
{
if (iVal == g_iOutput[i])
{
g_iIdx = i;
return true;
}
}
return false;
}
void GetEqualQueue(__int64 iInput)
{
g_iNum = 0;
g_iIdx = 0;
__int64 tmp = iInput;
g_iOutput[g_iNum++] = tmp;
while (1)
{
__int64 min = GetVal(tmp, Min);
__int64 max = GetVal(tmp, Max);
if (min == max) return;tmp = max-min;
g_iOutput[g_iNum] = tmp;
if (Check(tmp))
{
break;
}
g_iNum++;
}for (int i = g_iIdx; i < g_iNum; i++)
{
printf("%I64d ",g_iOutput[i]);
}
printf("\n");
}int main()
{
double iVal;
while (scanf("%lf",&iVal)==-1)
{}
GetEqualQueue((__int64)iVal);
return 0;
} -
02015-09-20 17:10:33@
#include <cstdio>
#include <algorithm>
#include <string>
#include <iostream>
#include <vector>using namespace std;
int k,k1;//记录 string长度和ans长度
string l;//用于第一次输入
vector<char>a;//存储l,sort排序
int i,j;//计数器
long long int m,n;//m最大值,n最小值
vector<long long int>ans;//最大值与最小值的差
long long int o;//同ans,用于计算inline void sscanf_vector(long long int &f,long long int &g)//排序后输入到n,m;f==n,g== m;
{
f=g=0;
for(j=0;j<k;++j)
{
f*=10;f+=((long long int)a[j]-(long long int)'0');
}
for(j=k-1;j>=0;--j)
{
g*=10;g+=((long long int)a[j]-(long long int)'0');
}
}inline int ans_jc(long long int nowans)//检查是否出现循环节
{
for(i=0;i<ans.size();++i)
{
if(ans[i]==nowans)return i;//返回循环节的开始位置
}
return -1;
}inline void coot(int beginn)//输出循环节
{
for(i=beginn;i<ans.size();++i)
{
cout<<ans[i]<<' ';
}
cout<<endl;
}void print() //数据处理
{
sort(a.begin(),a.end()); //先排序
sscanf_vector(n,m); //取出最大值最小值
if(ans_jc(m-n)!=-1) //判断是否出现循环节
{
int p=ans_jc(m-n); //循环节的开始位置
coot(p); //输出循环节
return;
}
else
{
o=m-n; //取出差
if(o==0) //出错情况
{
cout<<0;
return;
}
ans.push_back(o); //转存
k1=a.size(); //格式化动态数据数组方便递归
for(i=0;i<k1;++i) //格式化动态数据数组方便递归
{ //格式化动态数据数组方便递归
a.pop_back(); //格式化动态数据数组方便递归
} //格式化动态数据数组方便递归
k1=0; //计算o的长度(差的长度)
while(o!=0) //计算o的长度(差的长度)
{ //计算o的长度(差的长度)
o/=10; //计算o的长度(差的长度)
++k1; //计算o的长度(差的长度)
} //计算o的长度(差的长度)
o=ans[ans.size()-1]; //更新
long long int jan=1; //10^n
for(i=1;i<k1;++i) //10^n
{ //10^n
jan*=10; //10^n
} //10^n
for(;jan!=0;) //存o到a
{
int w=(o/jan)+48;
a.push_back(w);
o=o-(o/jan)*jan;
jan/=10;
} //存o到a
o=ans[ans.size()-1]; //更新
print(); //递归
}
return;
}int main()
{
while(cin>>l)//输入
{
k=l.length();//记录长度
for(i=0;i<k;++i)
{
a.push_back(l[i]);//转存
}
print();//对一个数的计算
k=a.size();
for(i=0;i<k;++i)
{
a.pop_back();
}
k=ans.size();
for(i=0;i<k;++i)
{
ans.pop_back();
}
}
return 0;
} -
02015-09-02 19:32:49@
珍爱时间,远离map;
-
02015-09-01 18:53:05@
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <sstream>
#include <set>
#include <vector>
#include <algorithm>
using namespace std;
const int MAXN = 1000 + 5;
long long n;
int main()
{
stringstream ss; ss.str("");ss.clear();
set<string> Set;
ios::sync_with_stdio(0);
string s;
vector<string> ans;
while (cin>>s) {
Set.clear(); ans.clear();
while (!Set.count(s)) {
long long Lnum=0,Gnum=0,td=0;
Set.insert(s);
ans.push_back(s);
string temp(s);sort(temp.begin(),temp.end());//greater
ss<<temp; ss>>Lnum; ss.str(""); ss.clear();reverse(temp.begin(),temp.end());
while(temp.length()<4)
temp+="0";
ss<<temp; ss>>Gnum; ss.str(""); ss.clear();td=Gnum-Lnum;
ss<<td; ss>>s; ss.str("");ss.clear();}
bool yes=false;
for (unsigned int i=0;i<ans.size();i++) {
if (ans[i]==s) yes=true;
if (yes) cout<<ans[i]<<' ';
}
cout<<endl;
}
return 0;
} -
02015-08-27 16:03:33@
c++ code
set<string> Set;
ios::sync_with_stdio(0);
string s;
vector<string> ans;
while (cin>>s) {
Set.clear(); ans.clear();
while (!Set.count(s)) {
Set.insert(s);
ans.push_back(s);
string a(s),b(s);
sort(a.rbegin(),a.rend());
sort(b.begin(),b.end());
//cout<<a<<' '<<b<<endl;
s=dec(a,b); //省略了dec函数的定义
//cout<<"the new s ="<<s<<endl;
}
bool o=0;
for (int i=0;i<ans.size();++i) {
if (ans[i]==s) o=1;
if (o) cout<<ans[i]<<' ';
}
cout<<endl;
}
return 0; -
02014-10-25 12:33:35@
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>void change(long long a,long long* max,long long* min);
int main()
{
while(1)
{
long long s[100],now;
int i,j;
int head,tail;
int flag = 0;
long long max = 0,min = 0;
if(scanf("%lld",&now)==EOF)
break;
s[0] = now;
change(now,&max,&min);
for(i = 1;i < 100;i++)
{
long long temp;
temp = max - min;
s[i] = temp;
change(temp,&max,&min);
for(j = i - 1;j >= 0;j--)
{
if(temp==s[j])
{
flag = 1;
head = j;
tail = i - 1;
break;
}
}
if(flag)
break;
}
for(i = head;i < tail;i++)
{
printf("%lld ",s[i]);
}
printf("%lld\n",s[tail]);
}
return 0;
}void change(long long a,long long* max,long long* min)
{
char str[100],t_str[100];
int i,j;
int len;
lltoa(a,str,10);
len = strlen(str);
for(i = 1;i < len;i++)
{
char key;
key = str[i];
j = i - 1;
while(key < str[j]&&j>=0)
{
str[j + 1] = str[j];
j--;
}
str[j + 1] = key;
}
for(i = len - 1,j = 0;i >= 0;i--,j++)
{
t_str[j] = str[i];
}
*min = atoll(str);
*max = atoll(t_str);
}要用long long,long是不够的
输入的数据可能包含在节点中,测试数据 #0: Accepted, time = 3 ms, mem = 524 KiB, score = 10
测试数据 #1: Accepted, time = 0 ms, mem = 520 KiB, score = 10
测试数据 #2: Accepted, time = 0 ms, mem = 528 KiB, score = 10
测试数据 #3: Accepted, time = 0 ms, mem = 524 KiB, score = 10
测试数据 #4: Accepted, time = 0 ms, mem = 520 KiB, score = 10
测试数据 #5: Accepted, time = 0 ms, mem = 532 KiB, score = 10
测试数据 #6: Accepted, time = 0 ms, mem = 528 KiB, score = 10
测试数据 #7: Accepted, time = 0 ms, mem = 532 KiB, score = 10
测试数据 #8: Accepted, time = 0 ms, mem = 528 KiB, score = 10
测试数据 #9: Accepted, time = 15 ms, mem = 528 KiB, score = 10
Accepted, time = 18 ms, mem = 532 KiB, score = 100 -
02014-10-22 19:23:55@
C++:
/*
纯模拟,开放式哈希评测结果
编译成功测试数据 #0: Accepted, time = 140 ms, mem = 16200 KiB, score = 10
测试数据 #1: Accepted, time = 109 ms, mem = 16200 KiB, score = 10
测试数据 #2: Accepted, time = 125 ms, mem = 16208 KiB, score = 10
测试数据 #3: Accepted, time = 62 ms, mem = 16208 KiB, score = 10
测试数据 #4: Accepted, time = 46 ms, mem = 16200 KiB, score = 10
测试数据 #5: Accepted, time = 62 ms, mem = 16208 KiB, score = 10
测试数据 #6: Accepted, time = 62 ms, mem = 16204 KiB, score = 10
测试数据 #7: Accepted, time = 46 ms, mem = 16208 KiB, score = 10
测试数据 #8: Accepted, time = 46 ms, mem = 16208 KiB, score = 10
测试数据 #9: Accepted, time = 62 ms, mem = 16208 KiB, score = 10
Accepted, time = 760 ms, mem = 16208 KiB, score = 100
*/
//====== CODE HERE ======
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <memory.h>#define MAXN 1000000
using namespace std;
long long h[MAXN + 1], list[MAXN + 1], ln, n, num[21], revpoint;
long long toh ( long long x )
{
if ( x <= MAXN )
return x;
else
return ( ( x + 25423 ) % MAXN );
}long long place ( long long x )
{
long long y = toh ( x );
while ( h[y] != -1 )
{
if ( list[h[y]] == x )
{
revpoint = y;
return -1;
}
++y;
if ( y > MAXN )
y = 0;
}
return y;
}void convert ( long long x )
{
n = ( x == 0 );
while ( x > 0 )
{
num[n++] = x % 10;
x /= 10;
}
}long long tobigger ( )
{
long long ans = 0;
for ( int i = n - 1; i >= 0; --i )
ans = ans * 10 + num[i];
return ans;
}long long tosmaller ( )
{
long long ans = 0;
for ( int i = 0; i < n; ++i )
ans = ans * 10 + num[i];
return ans;
}int main ( )
{
ios::sync_with_stdio ( false );
cin.tie ( NULL );long long a, i, k;
while ( cin >> a )
{
memset ( h, -1, sizeof ( h ) );
ln = 0;while ( true )
{
convert ( a );k = place ( a );
if ( k == -1 )
break;
h[k] = ln;
list[ln++] = a;sort ( num, num + n );
a = tobigger ( ) - tosmaller ( );
}for ( i = h[revpoint]; i < ln; ++i )
cout << list[i] << ' ';
cout << endl;
}return 0;
} -
02014-03-21 23:16:24@
program p1024;
var a:array[0..20000] of int64;
n,k:longint;
j:int64;
sj:string;
//
procedure swap(a,b:char;var c,d:char);
begin
c:=b;d:=a;
end;
//
function kk(aa:int64):int64;
var i,j,k:longint;
a1,a2:int64;
s1,s2,ss:string;
begin
str(aa,ss);s1:=ss;s2:=ss;k:=length(ss);
for i:=1 to k-1 do
for j:=i+1 to k do
begin
if s1[i]>s1[j] then swap(s1[i],s1[j],s1[i],s1[j]);
if s2[i]<s2[j] then swap(s2[i],s2[j],s2[i],s2[j]);
end;
val(s1,a1,i);val(s2,a2,i);
exit(abs(a1-a2));
end;
//
procedure make(j:int64);
var i:longint;
a3:int64;
t:boolean;
begin
t:=false;a[0]:=1;a[1]:=j;
while not(t) do
begin
a3:=kk(j);
for i:=1 to a[0] do
if a3=a[i] then
begin
t:=true;a[a[0]+1]:=i;break;
end;
if not(t) then
begin
inc(a[0]);a[a[0]]:=a3;j:=a3;
end;
end;
end;
//
procedure print;
var i:longint;
begin
for i:=a[a[0]+1] to a[0]-1 do write(a[i],' ');
writeln(a[a[0]]);
end;
//
begin
readln(sj);
while not(sj='') do
begin
val(sj,j,k);
make(j);
print;
readln(sj);
end;
end.