zoukankan      html  css  js  c++  java
  • 贪心/字符串处理 Codeforces Round #291 (Div. 2) A. Chewbaсca and Number

    题目传送门

     1 /*
     2     WA了好几次,除了第一次不知道string不用''外
     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]!=''; ++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 += '';
    39         cout << ans << endl;
    40     }
    41     
    42     return 0;
    43 }
    编译人生,运行世界!
  • 相关阅读:
    第四次作业
    随机点名
    表单验证
    冒泡排序&&选择排序
    Equals相等
    String类
    最终类final
    Eclipse的设置
    Equals相等(测试)
    猜数字
  • 原文地址:https://www.cnblogs.com/Running-Time/p/4366716.html
Copyright © 2011-2022 走看看