1023 Have Fun with Numbers

代码如下:

 1 #include
 2 #include<string>
 3 using namespace std;
 4 int trans(string &s){
 5     int jinwei = 0;
 6     string s1 = s;
 7     int x;
 8     for(int i = s.size()-1; i >= 0; i--){
 9         x = ((int)(s[i]-'0'))*2+jinwei;
10         if(x >= 10){
11             x -= 10;
12             jinwei = 1;
13             s[i] = (char)(x+'0');
14         }
15         else{
16             jinwei = 0;
17             s[i] = (char)(x+'0');
18         }
19     }
20     return jinwei;
21 }
22 int main(){
23     int a[10] = {0};
24     int b[10] = {0};
25     int c[100] = {1};
26     string n,m;
27     cin >> n;
28     m = n;
29     int stem = trans(m);
30 //    cout << m << endl;
31     if(stem == 1) b[1] = 1;
32     for(int i = 0; i < n.size(); i++){
33         a[(int)(n[i]-'0')] = 1;
34         b[(int)(m[i]-'0')] = 1;
35     }
36     //cout << stem << endl;
37     //trans(m);
38 //    for(int i = 0; i < x; i++){
39 //        int stem = n/c[x-1-i];
40 //        int ste = m/c[x-1-i];
41 //        cout << stem << " " << ste << endl;
42 //        a[stem]++;
43 //        b[ste]++;
44 //        m %= c[x-1-i];
45 //        n %= c[x-1-i];
46 //    }
47     bool flag = true;
48     for(int i = 0; i < 10; i++){
49         if(a[i] != b[i]){
50             flag = false;
51             cout << "No" << endl;
52             break;
53         }
54     }
55     if(flag) cout << "Yes" << endl;
56     if(stem == 1){
57         cout << "1" << m;
58     }
59     else cout << m;
60     return 0;
61 }

 

转载于:https://www.cnblogs.com/huhusw/p/9755185.html

你可能感兴趣的:(1023 Have Fun with Numbers)