zoukankan      html  css  js  c++  java
  • TOJ 3850: String Function Encoding

    传送门:http://acm.tzc.edu.cn/acmhome/problemdetail.do?&method=showdetail&id=3850

    时间限制(普通/Java):1000MS/3000MS     内存限制:65536KByte

    描述

    Bessie discovered a new function that the entire herd can apply to its character strings.
    Given both a number N (1 <= N <= 15) and a string S, with length strictly greater than N, define f(N, S) as a new string composed
    of the concatenation of the substring from character N (zero based -- first character is number 0) through the end of S and the string S itself.
    For example, with N = 2, and S = "COW", f(N, S) = "W" + "COW" = "WCOW". Also, f(3, "USACO") = "CO" + "USACO" = "COUSACO".
    Bessie is enthralled with this function and wants to iterate it several times. For example, if she iterates the function once for
    "COW" and N = 2, she will get "WCOW". If she applies the function with N = 2 again to that string, she will get "OWWCOW", and if she applies it one more time with N = 2, she will get "WCOWOWWCOW".
    Help Bessie encode a total of Z (1 <= Z <= 100) strings, str_1, str_2, and so on.  Each str_i has length in the range 2..100 and
    contains only upper case letters. Each string is presented with its own N_i (0 <= N_i < length(str_i), and iteration count C_i (1 <= C_i <= 12).

    输入

    * Line 1: A single integer: Z
    * Lines 2..Z+1: Line i+1 contains two space-separated integers, a space, and string to be encoded: N_i, C_i, and str_i

    输出

    * Lines 1..Q: Line j contains the iterated, encoded version of str_j

    样例输入

    样例输出

    提示

    OUTPUT DETAILS:
    The arrow denotes an iteration of the function

    COW -> WCOW -> OWWCOW -> WCOWOWWCOW

    USACO -> COUSACO -> SACOCOUSACO

    题意:就是把得到的字符串的 从N开始到串结束 这个子串,截取来,放到该串的最前面,这算一次操作

              比如说第一组数据,N = 2 ,F =3 代表要执行3次,每次把  第二个位置到最后一位 的子串,截取下来,放到最前面。

    思路:拿string里面的substr和insert ,截取和插入一下就好了,水题!

    #include<iostream>
    #include<algorithm>
    #include<string>
    #include<cstdio>
    #include<cstring>
    using namespace std;
    int main()
    {
       int m,k,T,n; scanf("%d",&T); while(T--) { string s; scanf("%d %d",&n,&m); cin>>s; int t = n; while(m--) { string s1 = s.substr(t,s.size()-t+1); s.insert(0,s1); } cout<<s<<endl; } }
  • 相关阅读:
    【Spring Framework】10、代理模式
    【Spring Framework】8、使用注解开发
    Codeforces 516E
    AtCoder Grand Contest 055 题解
    Codeforces 1606F
    贪心/构造/DP 杂题选做
    整数拆分最大乘积
    CSP-S2021 被碾压记
    洛谷 P2791
    LCT 小记
  • 原文地址:https://www.cnblogs.com/Esquecer/p/8495035.html
Copyright © 2011-2022 走看看