zoukankan      html  css  js  c++  java
  • 牛客网 2018年全国多校算法寒假训练营练习比赛(第二场) A.吐泡泡-STL(stack)

    不好玩,一堆板子,太菜了,被打爆了,B一直wa60%,D一直wa80%,D改了多组输入就过了。。。

    A.吐泡泡
     
     
    时间限制:C/C++ 1秒,其他语言2秒
    空间限制:C/C++ 32768K,其他语言65536K
    64bit IO Format: %lld

    题目描述

    小鱼儿吐泡泡,嘟嘟嘟冒出来。小鱼儿会吐出两种泡泡:大泡泡"O",小泡泡"o"。
    两个相邻的小泡泡会融成一个大泡泡,两个相邻的大泡泡会爆掉。
    (是的你没看错,小气泡和大气泡不会产生任何变化的,原因我也不知道。)
    例如:ooOOoooO经过一段时间以后会变成oO。

    输入描述:

    数据有多组,处理到文件结束。
    每组输入包含一行仅有'O'与'o'组成的字符串。

    输出描述:

    每组输出仅包含一行,输出一行字符串代表小鱼儿吐出的泡泡经过融合以后所剩余的泡泡。
    示例1

    输入

    ooOOoooO

    输出

    oO

    说明

    自左到右进行合并




    这个题一开始算的样例结果发现和给的答案不对,结果是样例错了。从左到右的强制性要求。

    
    
    

    代码:

     1 #include<iostream>
     2 #include<cstdio>
     3 #include<algorithm>
     4 #include<cstring>
     5 #include<cstdlib>
     6 #include<string.h>
     7 #include<set>
     8 #include<vector>
     9 #include<queue>
    10 #include<stack>
    11 #include<map>
    12 #include<cmath>
    13 using namespace std;
    14 typedef long long ll;
    15 const int inf=0x3f3f3f3f;
    16 double PI=acos(-1.0);
    17 const int maxn=1e5+100;
    18 int main(){
    19     stack<char> s;
    20     string c;
    21     while(cin>>c){
    22         while(!s.empty()) s.pop();
    23         for(int i=0;i<c.size();i++){
    24             if(s.empty()){
    25                 if(c[i]=='o') s.push('o');
    26                 else s.push('O');
    27                 continue;
    28             }
    29             if(s.top()==c[i]){
    30                 if(c[i]=='o'){
    31                     s.pop();
    32                     s.push('O');
    33                 }
    34                 else s.pop();
    35                 char pd;
    36                 while(s.size()>=2){
    37                     pd=s.top();
    38                     s.pop();
    39                     if(pd==s.top()){
    40                         if(pd=='o'){
    41                             s.pop();
    42                             s.push('O');
    43                         }
    44                         else s.pop();
    45                     }
    46                     else
    47                     {
    48                         s.push(pd);
    49                         break;
    50                     }
    51                 }
    52             }
    53             else{
    54                 if(c[i]=='o') s.push('o');
    55                 else s.push('O');
    56             }
    57         }
    58         int e=0;
    59         char b[10000];
    60         while(!s.empty()){
    61             b[e++]=s.top();
    62             s.pop();
    63         }
    64         for(int i=e-1;i>=0;i--) cout<<b[i];
    65         cout<<endl;
    66     }
    67 }
    
    
    
    
    
    
     
  • 相关阅读:
    JSON使用——获取网页返回结果是Json的代码
    关于android:inputType属性的说明
    MySQL无视密码进入Server
    Linux下MySQL使用
    Linux下mv命令详解
    软件测试:测试用例
    软件测试:概述
    《零售业务中台架构设计探讨及实践》阅读笔记
    Python开发:OpenCV版本差异所引发的cv2.findContours()函数传参问题
    《小米网抢购系统开发实践》阅读笔记
  • 原文地址:https://www.cnblogs.com/ZERO-/p/8376920.html
Copyright © 2011-2022 走看看