A. Scarborough Fair

Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get there.
Willem asks his friend, Grick for directions, Grick helped them, and gave them a task.
Although the girl wants to help, Willem insists on doing it by himself.
Grick gave Willem a string of length n.
Willem needs to do m operations, each operation has four parameters l, r, c1, c2, which means that all symbols c1 in range [l, r] (from l-th to r-th, including l and r) are changed into c2. String is 1-indexed.
Grick wants to know the final string after all the m operations.

Input
The first line contains two integers n and m (1 ≤ n, m ≤ 100).

The second line contains a string s of length n, consisting of lowercase English letters.

Each of the next m lines contains four parameters l, r, c1, c2 (1 ≤ l ≤ r ≤ n, c1, c2 are lowercase English letters), separated by space.

Output
Output string s after performing m operations described above.

Examples
inputCopy
3 1
ioi
1 1 i n
outputCopy
noi
inputCopy
5 3
wxhak
3 3 h x
1 5 x a
1 3 w g
outputCopy
gaaak
Note
For the second example:
After the first operation, the string is wxxak.
After the second operation, the string is waaak.
After the third operation, the string is gaaak.

#include <iostream>
#include <string>
using namespace std;

int main()
{
    int n, m;
    while(cin >> n >> m)
    {
        string s;
        cin >> s;
        for(int i = 0; i < m; ++i)
        {
            int L, R;
            char fro, bac;
            cin >> L >> R >> fro >> bac;
            for(int j = L - 1; j <= R - 1; ++j)
                if(s[j] == fro )
                    s[j] = bac;
        }
        cout << s << '\n';
    }
    return 0;
}

全部评论

相关推荐

阿武同学:基本信息保留前面三行,其他的可以全部删掉,邮箱最重要的你没写,主修课程精简到8个以内,实习里面2/3/4都是水内容的,非要写的话建议两到三句话,项目经历排版优化下,自我评价缩到三行
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务