• 今日sb题之 sdnuoj 1064


     

     1 #include <iostream>
     2 #include <string>
     3 #include <stdio.h>
     4 #include <cmath>
     5 #include <algorithm>
     6 using namespace std;
     7 
     8 bool judge(string &s)
     9 {
    10     if ( abs (count(s.begin(),s.end(),'B') - (count(s.begin(), s.end(), 'G') ) == 1) || count(s.begin(), s.end(), 'B') == (count(s.begin(), s.end(), 'G')))
    11         return true;
    12     else
    13         return false;
    14 }
    15 
    16 
    17 void printans(string &s)
    18 {
    19 
    20     if (count(s.begin(), s.end(), 'B') - count(s.begin(), s.end(), 'G') == 1)
    21     {
    22         int n = count(s.begin(), s.end(), 'B');
    23         for (int i = 0; i < n-1; i++)
    24             cout << "BG";
    25         cout << "B" << endl;
    26     }
    27     if (count(s.begin(), s.end(), 'B') - count(s.begin(), s.end(), 'G') == -1)
    28     {
    29         int n = count(s.begin(), s.end(), 'G');
    30         for (int i = 0; i < n-1 ; i++)
    31             cout << "GB";
    32         cout << "G" << endl;
    33     }
    34     if (count(s.begin(), s.end(), 'B') == count(s.begin(), s.end(), 'G'))
    35     {
    36         int n = count(s.begin(), s.end(), 'G');
    37         for (int i = 0; i < n ; i++)
    38             cout << "BG";
    39         printf("
    ");
    40     }
    41 
    42 }
    43 
    44 
    45 
    46 
    47 
    48 int main()
    49 {
    50 
    51         string s;
    52         while(cin >> s)
    53         {
    54             if (judge(s))
    55                 printans(s);
    56             else
    57                 cout << "No" << endl;
    58 
    59         } 
    60         
    61         
    62 
    63 
    64     return 0;
    65 }

    WA 了

    我就是想复习复习string 

  • 相关阅读:
    MySQL学习笔记(六):索引
    正则表达式基础知识,持续更新…
    js改变盒子大小(上下左右)分析
    表单自定义样式
    js拖拽分析
    javascript右键菜单分析
    简要分析javascript的选项卡和轮播图
    表单联动的总结
    浅显总结ASCII Unicode UTF-8的区别
    瀑布流知识的延伸
  • 原文地址:https://www.cnblogs.com/ranzhong/p/13753966.html
Copyright © 2020-2023  润新知