当前位置:网站首页>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;
}
边栏推荐
- Characteristics of transactions -- atomicity (implementation principle)
- Leetcode question brushing 07 double pointer
- How many times does the constructor execute?
- Leetcode-12- integer to Roman numeral (medium)
- Mysql database listening -canal
- Addition and modification of JPA
- 工作与生活
- Leetcode-15- sum of three numbers (medium)
- Argparse command line passes list type parameter
- leetcode. 349. intersection of two arrays
猜你喜欢
随机推荐
Application advantages of 5g industrial gateway in coal industry
Continue when the condition is not asked, execute the parameter you compare
pycharm add configutions
Leetcode 05 tree
Ecological convergence NFT attacks, metaverse ape leads the new paradigm revolution of Web 3.0 meta universe
Memory learning book reference
Remove duplicates from an ordered array
Status of the thread
Transaction characteristics and isolation levels
leetode. 242. valid Letter heteronyms
Exercise 5.14 input n strings, arrange them in alphabetical order and output them.
FLIP动画实现思路
Wikipedia User Guide
使用Pygame创建一个简单游戏界面
Rasa dialogue robot helpdesk (III)
How to solve the problems when using TV focusable to package APK in uni app
Web Application & applet application deployment
切线与切平面
他山之石:a16z 的 Web3 投资版图
spiral matrix visit Search a 2D Matrix