T4310 Zuma game and t4310 Zuma game

Source: Internet
Author: User

T4310 Zuma game and t4310 Zuma game
Description

Zuma is a game that once swept the world. Its gameplay is: initially arranged on a certain track

Colored beads. Any of the three adjacent beads will not be exactly the same color. After that, you can launch beads

Orbit and add it to the original sequence. Once three or more beads of the same color become adjacent, they will

It disappears. This type of elimination may occur in a chain, during which you will not be able to launch beads for the moment.

The developer recently prepared to write a playback tool for the player's game process. They have completed in-game

The process record function is provided, and the implementation of the playback function is entrusted to you.

In the record of the game process, the first is the initial bead sequence on the track, and the second is what the player will do next.

. Your task is to calculate the new bead sequence in time after each operation.

Input/Output Format Input Format:

The first line is an uppercase letter 'A '~ A string consisting of 'Z', indicating the initial bead sequence on the orbit,

Different letters indicate different colors.

The second row is a number n, indicating that there are n operations throughout the playback process.

The next n rows correspond to each operation in turn. Each operation consists of a number k and an uppercase letter Σ

Description, separated by spaces. Where, Sigma is the color of the new beads. If a total of m beads exist before insertion, then k * [0, m]

Indicates the order in orbit after the new beads are embedded (before they are eliminated.

Output Format:

N rows are output, and each operation (and possible elimination) is given in sequence.

Of the beads.

If no beads exist on the orbit, it is expressed.

Input and Output sample Input example #1:
ACCBA51 B0 A2 B4 C0 A
Output sample #1:
ABCCBAAABCCBAAABBCCBA-A
Description

100% of the data must be 1 ≤ n ≤ 10 ^ 3, 0 ≤ m ≤ 2 × 10 ^ 3.

 

 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 using namespace std; 5 int where; 6 int flag=0; 7 string c; 8 string a; 9 int n;10 void pd()11 {12     int tot=1;13     do14     {15         flag=0;16         tot=1;17         int h=where-1,t=where+1,now=where;18         while(a[h]==a[now]&&h>=0)19         {20             tot++;21             h--;22         }23         h++;24         while(a[t]==a[now]&&t<a.size())25         {26             tot++;27             t++;28         }29         t--;30         if(tot>=3)31         {32             //cout<<endl<<a<<"******"<<endl;33             a.erase(h,tot);34             flag=1;35             //cout<<endl<<a<<"-------"<<endl;36         }37         where=h;38     }while(flag==1);39 40 }41 int main()42 {43     getline(cin,a);44     scanf("%d",&n);45     while(n--)46     {47         cin>>where>>c;48         a.insert(where,c);49         pd();50         if(a.size()==0)51         cout<<"-"<<endl;52         else cout<<a<<endl;53     }54     return 0;55 }

 

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.