Codeforces Round #479 (Div. 3) A. Wrong Subtraction

Problem URL: http://codeforces.com/contest/977/problem/A

 

Solution: Give you a number n, perform k transformations, starting from the end -1,512 becomes 511, 511 becomes 510, and 510 will eliminate 0. (You should be able to understand if you look at the Note~)

Method: water question. . . The number is read in as a string, and if the end is 0, the length of the string is -1, otherwise -1. Then if len<=0, it will output 0 (I don't know why it can be passed without <0, maybe this situation will not occur?), otherwise, it can be output one by one according to the length~

 1 #include<cstdio>
 2 #include<cmath>
 3 #include<algorithm>
 4 #include<cstring>
 5 #include<string>
 6 #include<iostream>
 7 #include<map>
 8 #include<vector>
 9 #include<set>
10 #include<queue>
11 using namespace std;
12 int main()
13 {
14     char n[10];
15     int  k;
16     cin >> n >> k;
17      int len ​​= strlen (n);
18      while (k-- )
 19      {
 20          if (n [len - 1 ] == ' 0 ' )
 21          {
 22              len-- ;
23          }
 24          else 
25          {
 26              n [len - 1 ] - = 1 ;
27          }
 28      }
 29      if (only == 0 )
 30          printf ( "0\n");
31     else
32     {
33         for (int i = 0; i < len; i++)
34         {
35             printf("%c", n[i]);
36         }
37         printf("\n");
38     }
39     
40     return 0;
41 }

 

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325727619&siteId=291194637