2018 National multi-school algorithm winter training Camp Practice Competition (second session) A. Spit Bubbles

Source: Internet
Author: User

Link to original topic

Describe

Small fish spit bubble, toot toot out. Small fish will spit out two kinds of bubbles: Big bubble "o", Small bubble "O".
Two adjacent small bubbles will melt into a large bubble, two adjacent large bubbles will explode.
(Yes, you're right, little bubbles and bubbles don't make any difference, and I don't know why.) )
Note: Merge from left to right.
For example: Oooooooo will become OO after a period of time.

Input

The data has multiple groups and is processed to the end of the file.
Each set of inputs contains a single row of ' O ' and ' O ' strings.

Output

Each set of outputs contains only one row, and the output line string represents the bubbles that the small fish spit out after fusion.

Sample input

Oooooooo

Sample output

Oo

Ideas

Using the stack simulation is good, water problem

Code
#include <bits/stdc++.h>#define ll long longusing namespace std;void check(char ans[], int len){    if(len == 0) return;    while(ans[len] == ans[len-1])    {        ans[len] = ‘\0‘; len--;        if(ans[len] == ‘o‘) ans[len] = ‘O‘;        else ans[len--] = ‘\0‘;        if(len <= 0) return;    }}int main(){    char s[102];    while(~scanf("%s", s))    {        char ans[102];        int f = 1;        while(f)        {            memset(ans,0,sizeof(ans));            ans[0] = s[0]; int j = 1; f = 0;            int len = strlen(s);            for(int i = 1; i < len; i++)            {                int j = strlen(ans);                ans[j] = s[i];                check(ans, j);            }            memset(s,0,sizeof(s));            for(j = 0; ans[j] != ‘\0‘; j++)                s[j] = ans[j];            s[j] = ‘\0‘;        }        printf("%s\n", s);    }    return 0;}

2018 National multi-school algorithm winter training Camp Practice Competition (second session) A. Spit Bubbles

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.