zoukankan      html  css  js  c++  java
  • Educational Codeforces Round 1 B. Queries on a String 暴力

    B. Queries on a String

    Time Limit: 20 Sec

    Memory Limit: 256 MB

    题目连接

    http://codeforces.com/contest/598/problem/B

    Description

    You are given a string s and should process m queries. Each query is described by two 1-based indices liri and integer ki. It means that you should cyclically shift the substring s[li... riki times. The queries should be processed one after another in the order they are given.

    One operation of a cyclic shift (rotation) is equivalent to moving the last character to the position of the first character and shifting all other characters one position to the right.

    For example, if the string s is abacaba and the query is l1 = 3, r1 = 6, k1 = 1 then the answer is abbacaa. If after that we would process the query l2 = 1, r2 = 4, k2 = 2 then we would get the string baabcaa.

    Input

    The first line of the input contains the string s (1 ≤ |s| ≤ 10 000) in its initial state, where |s| stands for the length of s. It contains only lowercase English letters.

    Second line contains a single integer m (1 ≤ m ≤ 300) — the number of queries.

    The i-th of the next m lines contains three integers liri and ki (1 ≤ li ≤ ri ≤ |s|, 1 ≤ ki ≤ 1 000 000) — the description of the i-th query.

    Output

    Print the resulting string s after processing all m queries.

    Sample Input

    abacaba
    2
    3 6 1
    1 4 2

    Sample Output

    baabcaa

    HINT

    题意

    给你一个字符串,然后有Q次操作,每次操作可以使得区间的字符串向右平移K个字符

    然后问你最后的字符是什么模样

    题解:

    询问只有300个,所以可以直接暴力就好了

    代码

    #include<iostream>
    using namespace std;
    
    int main()
    {
        string s1,s2;
        cin>>s1;
        s2=s1;
        int q;cin>>q;
        while(q--)
        {
            int l,r,k;cin>>l>>r>>k;
            l--,r--;
            int len = r-l+1;k%=len;
            for(int i=0;i<len;i++)
            {
                s2[(i+k)%len+l]=s1[l+i];
            }
            for(int i=l;i<=r;i++)
                s1[i]=s2[i];
        }
        cout<<s1<<endl;
    }
  • 相关阅读:
    遇到的面试题目
    获取本机IP_考虑多网卡的情况
    C#发送电子邮件
    C#获取局域网中的所有正在使用的IP地址
    C#获取本机IP且过滤非真实网卡(如虚拟机网卡)
    C#获取本机的MAC地址
    C#获取本机磁盘信息
    C#获得系统打开的端口和状态
    C#通过编程方式实现Ping
    千万不要使用xfce和KDE版Manjaro Linux--之荒谬言论
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4966139.html
Copyright © 2011-2022 走看看