当前位置:网站首页>Spit bubbles (stack)
Spit bubbles (stack)
2022-06-13 01:25:00 【Python's path to becoming a God】
Title Description
Little fish spit bubbles , Doodle, doodle, doodle, doodle . Small fish will spit out two kinds of bubbles : Big bubbles "O", Small bubble "o".
Two adjacent small bubbles will melt into a big bubble , Two adjacent large bubbles will burst .
( Yes, you are right , Small bubbles and large bubbles will not produce any change , I don't know why .)
for example :ooOOoooO After a period of time, it will become oO.
Input description :
There are multiple sets of data , Processing to the end of the file .
Each set of inputs contains one line and only ’O’ And ’o’ Composed string .
Output description :
Each set of output contains only one line , Output a line of string representing the bubbles spit out by the small fish and the remaining bubbles after fusion .
Example
Input :
ooOOoooO
Output :
oO
Ideas
I think the stack is more suitable , Read in... One by one , If the current stack top is a small bubble , The next one is a small bubble, and the top of the stack is changed to a large bubble ; If you enter a big bubble, you don't understand ; If the top of the stack is a big bubble, it is slightly ; Finally, just output the stack
Code
Here is a set of input codes , If there are multiple groups of input, you have to change
#include<bits/stdc++.h>
using namespace std;
int main()
{
stack<char> s;
char c;
while(cin>>c)
{
if(s.empty()){
s.push(c);continue;}
if(s.top()=='o')
{
if(c=='o')
{
s.pop();
if(s.empty())
{
s.push('O');
}
else if(s.top()!='O')s.push('O');
else{
s.pop();}
}
else
{
s.push(c);
}
continue;
}
else if(s.top()=='O')
{
if(c=='O')
{
s.pop();
}
else
{
s.push(c);
}
}
}
int n=s.size();
char* q=(char*)malloc(sizeof(char)*n);
char t;
for(int i=0;i<n;i++)
{
t=s.top();
s.pop();
q[i]=t;
}
for(int i=n-1;i>=0;i--)
{
cout<<q[i];
}
return 0;
}
边栏推荐
- ArrayList underlying source code
- [latex] insérer une image
- 论文笔记:STMARL: A Spatio-Temporal Multi-AgentReinforcement Learning Approach for Cooperative Traffic
- Simple operation of MySQL database
- Plusieurs catégories de tests logiciels sont claires à première vue
- Leetcode-14- longest common prefix (simple)
- QT color extraction
- Realization of flip animation
- Redis usage optimization summary learning
- 项目实训(十七)---个人工作总结
猜你喜欢

Crypto JS reports uglifyjs error

使用Pygame创建一个简单游戏界面
![[leetcode] valid phone number Bash](/img/f8/cecb74f9d8f7c589e62e3a9a874f82.jpg)
[leetcode] valid phone number Bash

ES6 deconstruction assignment

Happy string

Wal mechanism of MySQL

MySQL related summary

Alexnet implements image classification of caltech101 dataset (pytorch Implementation)

Large end storage and small end storage

Leetcode question brushing 03 stack
随机推荐
Transaction characteristics and isolation levels
Facial expression recognition dataset
Leetcode 01 array
Sliding window summary of TCP connections
软件测试的几种分类,一看就明了
Characteristics of transactions - persistence (implementation principle)
redis
How many times does the constructor execute?
Wangdao machine test - Chapter 6 - maximum common divisor GCD and minimum common multiple LCM
Rasa dialogue robot helpdesk (III)
Calculate sentence confusion ppl using Bert and gpt-2
September 3, 2021 visual notes
Status of the thread
Several categories of software testing are clear at a glance
軟件測試的幾種分類,一看就明了
Wikipedia User Guide
Install pycharm process
Network communication tcp/ip
数学知识整理:极值&最值,驻点,拉格朗日乘子
Leetcode-11- container with the most water (medium)