• Codeforces Round #449 (Div. 2)AB


    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
    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.

    给定n长度的字符串和m个操作。每个操作让(l,r)之间的c1变成c2.

     1 #include <bits/stdc++.h>
     2 using namespace std;
     3 char str[110];
     4 int main() {
     5     int n, m;
     6     cin >> n >> m;
     7     cin >> str;
     8     while(m--) {
     9         int l, r;
    10         char c1, c2;
    11         cin >> l >> r >> c1 >> c2;
    12         for(int i = l; i <= r; i ++) {
    13             if(str[i-1] == c1) str[i-1] = c2;
    14         }
    15     }
    16     cout << str << endl;
    17     return 0;
    18 }
    B. Chtholly's request

    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, .

    求前k个palindrome之和并模p,palindrome的定义是回文数并且字符个数是偶数。

    从i等于1开始到k,让i反转并而i组成一个数。

     1 #include <bits/stdc++.h>
     2 #define ll long long
     3 using namespace std;
     4 ll b[11];
     5 int main() {
     6     ll k, p,i;
     7     cin >> k >> p;
     8     ll ans = 0;
     9     for(i = 1; i <= k ; i ++) {
    10         ll tmp = i, cnt = 0;
    11         while(tmp > 0) {
    12             b[cnt++] = tmp % 10;
    13             tmp /= 10;
    14         }
    15         ll xx = 1;
    16         for(int j = 0; j < cnt; j ++) {
    17             tmp = tmp*10 + b[j];
    18             xx *= 10;
    19         }
    20         cnt = i;
    21         ans += cnt*xx+tmp;
    22         //cout << tmp*xx+cnt << endl;
    23         ans %= p;
    24     }
    25     cout << (ans+p)%p  << endl;
    26     return 0;
    27 }
  • 相关阅读:
    VUE16 检测数据变化的原理
    Pytorch入门
    Redis安装,可视化和配置
    Dapper库的学习参考
    LeetCode148. Sort List 单链表排序
    xcode 添加copy files 时签名失败
    Python 3网络爬虫开发实战崔庆才
    项目管理【79】 | 知识产权与标准规范政府采购法法
    项目管理【81】 | 项目立项管理
    项目管理【78】 | 知识产权与标准规范招投标法
  • 原文地址:https://www.cnblogs.com/xingkongyihao/p/8024770.html
Copyright © 2020-2023  润新知