贪心/字符串处理 Codeforces Round #291 (Div. 2) A. Chewbaсca and Number

 

题目传送门

 1 /*
 2     WA了好几次,除了第一次不知道string不用'\0'外
 3     都是欠考虑造成的
 4 */
 5 #include <cstdio>
 6 #include <cmath>
 7 #include <string>
 8 #include <cstring>
 9 #include <iostream>
10 #include <algorithm>
11 #include <map>
12 #include <set>
13 #include <vector>
14 using namespace std;
15 
16 int main(void)
17 {
18     //freopen ("A.in", "r", stdin);
19     
20     string s, ans;
21     
22     while (getline (cin, s))
23     {
24         ans = "";
25         for (int i=0; s[i]!='\0'; ++i)
26         {
27             int x = s[i] - '0';
28             if (x > (9 - x))
29             {
30                 if (i == 0 && x == 9)
31                     ans += s[i];
32                 else
33                     ans += ((9 - x) + '0');
34             }
35             else
36                 ans += s[i];
37         }
38         //ans += '\0';
39         cout << ans << endl;
40     }
41     
42     return 0;
43 }

 

posted @ 2015-03-25 19:38  Running_Time  阅读(86)  评论(0编辑  收藏  举报