标签:构造
题目链接:http://lx.lanqiao.org/problem.page?gpid=T113
#include<iostream> #include<string> #define N 1000000 using namespace std; int pos=0,n; class Node{ public: int sum; string num; void Calc(int k,int flag){ string str="",tmp=""; while(k) { str+='0'+k%10; k/=10; } tmp+=str[2]; tmp+=str[1]; if(flag){ str=tmp+str; } else str=tmp+str[0]+str; num=str; } void CalcBit(){ string s=num; int total=0,len=s.size(); for(int i=0;i<len;i++) total+=s[i]-'0'; sum=total; } }x[N]; void init(){ for(int i=100;i<1000;i++){ x[pos].Calc(i,1); x[pos++].CalcBit(); } for(int i=100;i<1000;i++){ x[pos].Calc(i,0); x[pos++].CalcBit(); } } int main() { init(); cin.sync_with_stdio(false); cin>>n; int flag=1; for(int i=0;i<pos;i++) if(x[i].sum==n)cout<<x[i].num<<endl,flag=0; if(flag)cout<<-1<<endl; return 0; }
<span style="color: rgb(51, 51, 51); font-family: 宋体, 'Times New Roman';font-size:18px; line-height: 18.5714302062988px;">出处:</span><a target=_blank href="http://blog.csdn.net/mummyding" style="font-family: 宋体, 'Times New Roman';font-size:18px; line-height: 18.5714302062988px;">http://blog.csdn.net/mummyding</a><span style="color: rgb(51, 51, 51); font-family: 宋体, 'Times New Roman';font-size:18px; line-height: 18.5714302062988px;"> </span>
作者:MummyDing
标签:构造
原文地址:http://blog.csdn.net/mummyding/article/details/44423035