Codeforces Round #449 (Div. 2)

A. Scarborough Fair
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
Are you going to Scarborough Fair?

Parsley, sage, rosemary and thyme.

Remember me to one who lives there.

He once was the true love of mine.

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
Input
3 1
ioi
1 1 i n
Output
noi
Input
5 3
wxhak
3 3 h x
1 5 x a
1 3 w g
Output
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.

直接替换

 1 #include <iostream>
 2 #include <cstring>
 3 
 4 using namespace std;
 5 int n,m;
 6 string s;
 7 int main(){
 8     cin>>n>>m>>s;
 9     int left,right,c1,c2;
10     while(m--){
11         char c1,c2;
12         cin>>left>>right>>c1>>c2;
13         for(int i=left-1;i<=right-1;i++)
14             if(s[i]==c1)
15                 s[i]=c2;
16     }
17     cout<<s<<endl;
18     return 0;
19 }
B. Chtholly's request
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
— Thanks a lot for today.

— I experienced so many great things.

— You gave me memories like dreams... But I have to leave now...

— One last request, can you...

— Help me solve a Codeforces problem?

— ......

— What?

Chtholly has been thinking about a problem for days:

If a number is palindrome and length of its decimal representation without leading zeros is even, we call it a zcy number. A number is palindrome means when written in decimal representation, it contains no leading zeros and reads the same forwards and backwards. For example 12321 and 1221 are palindromes and 123 and 12451 are not. Moreover, 1221 is zcy number and 12321 is not.

Given integers k and p, calculate the sum of the k smallest zcy numbers and output this sum modulo p.

Unfortunately, Willem isn't good at solving this kind of problems, so he asks you for help!

Input

The first line contains two integers k and p (1 ≤ k ≤ 105, 1 ≤ p ≤ 109).

Output

Output single integer — answer to the problem.

Examples
Input
2 100
Output
33
Input
5 30
Output
15
Note

In the first example, the smallest zcy number is 11, and the second smallest zcy number is 22.

In the second example, .

数据转换,注意思维;

 1 #include <iostream>
 2 #include <cstring>
 3 #include <cstdio>
 4 #include <algorithm>
 5 #include <cmath>
 6 #define ll long long int
 7 using namespace std;
 8 ll n,m;
 9 string ting(ll x){
10     string s;
11     while(x){
12         char c=x%10+'0';
13         x/=10;
14         s+=c;
15     }
16     return s;
17 }
18 ll init(string s){
19     ll x=0;
20     for(int i=0;i<s.length();i++){
21         x=x*10+(s[i]-'0');
22     }
23     return x;
24 }
25 ll Pow(ll x){
26     ll an=1;
27     while(x--){
28         an=(an*10);
29     }
30     return an;
31 }
32 int main(){
33     std::ios::sync_with_stdio(false);
34     cin>>n>>m;
35     ll sum=0;
36     for(int i=1;i<=n;i++){
37         ll x=i;
38         string s=ting(x);
39         ll slen=s.length();
40         ll an=Pow(slen);
41         ll bn=(init(s));
42         sum+=(i*an+bn)%m;
43     }
44      cout<<sum%m<<endl;
45     return 0;
46 }
原文地址:https://www.cnblogs.com/zllwxm123/p/7965854.html