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
样例输入
2
2 3 COW
3 2 USACO
样例输出
WCOWOWWCOW
SACOCOUSACO
提示
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+);
s.insert(,s1);
}
cout<<s<<endl;
}
}
TOJ 3850: String Function Encoding的更多相关文章
- SQL:Example Uses of the SUBSTRING String Function
---Example Uses of the SUBSTRING String Function --http://www.sql-server-helper.com/tips/tip-of-the- ...
- FromBase64String(String)和Encoding.Default.GetBytes(String)
今天突然被问FromBase64String(String)和Encoding.Default.GetBytes(String)有啥区别,我刚开始学C#对这个一脸懵逼,于是总结一下今天查资料的内容. ...
- [转]Date and String Function in BluePrism
本文转自:https://www.codeproject.com/Articles/1247389/Date-and-String-Function-in-BluePrism This article ...
- csharp: string Encoding
/// <summary> /// 中文转unicode /// </summary> /// <param name="str"></p ...
- Node.js Base64 Encoding和Decoding
如何在Node.js中encode一个字符串呢?是否也像在PHP中使用base64_encode()一样简单? 在Node.js中有许多encoding字符串的方法,而不用像在JavaScript中那 ...
- Base64 Encoding / Decoding in Node.js
Posted on April 20th, 2012 under Node.js Tags: ASCII, Buffer, Encoding, node.js, UTF So how do you e ...
- Decode String
Given an encoded string, return it's decoded string.The encoding rule is: k[encoded_string], where t ...
- DiscuzX /source/function/function_core.php通用核心函数库文件分析
... <?php /** * [Discuz!] (C)2001-2099 Comsenz Inc. * This is NOT a freeware, use is subject to l ...
- Chromium String usage
For Developers > Chromium String usage Types of StringsIn the Chromium code base, we use std:: ...
随机推荐
- awk的用法
awk是什么 awk是一种优良的文本处理工具,同时也是一种脚本语言.awk的三位作者者已将它正式定义为“样式扫描和处理语言”.awk脚本允许您创建简短的程序,这些程序读取输入文件.为数据排序.处理数据 ...
- C++/C#:类Class与结构体Struct的区别
C++中: 默认的访问控制.继承访问权限不同:struct时public的,class时 private的: 其它基本一样. C#中: struct是值类型,class是引用类型的: struct S ...
- UnicodeDecodeError: 'ascii' codec can't decode byte 0x9c in position 1: ordinal not in range(128)
待研究: compressed_data = zlib.compress(json.dumps(data), 9) file_data = MySQLdb.escape_string(compress ...
- python流程控制while和if
流程控制 1.流程控制if if的4种语法 语法1: #结构形式 #if条件: # 代码1 # 代码2 # 代码3 # ... key_bak=123 key=int(input('key:')) ...
- Linux:简单的并发服务器实现
我前两天实现了一个简单的服务器和一个对应的客户端,也简单的解决了一些错误检查和常用的函数的封装,但是那个服务器的一次只能连接一个客户端,鸡肋,太鸡肋了,今天我来实现可以连接多个客户端的服务器实例:多进 ...
- UNITY 的GC ALLOC到底是什么
U3D的Profiler中的GC ALLOC 项让人很麻烦,一直搞不清楚它是什么,因为 GC 是垃圾回收,而alloc是内存分配,那么 GC ALLOC 是 垃圾回收内存分配? 这个名字起的太TM烂了 ...
- Java IO中转换流的作用
在<Java网络编程>中,有这样一段话: ”Reader和Writer最重要的子类是InputStreamReader和OutputStreamWriter类. InputStreamRe ...
- Object-c 调用unity的 UIViewController和UnitySendMessage
.mm文件中实现 #import <UIKit/UIKit.h> extern UIViewController *UnityGetGLViewController(); extern & ...
- vscode 右击文件||文件夹添加快捷方式
操作注册表步骤 1.按下win+R 2.输入redegit,打开注册表 3.找到HKEY_CLASSES_ROOT/*/shell路径 4.新建/项:命名Open with visual code 5 ...
- 一个神奇的BUG :Failed to finalize session : INSTALL_FAILED_INVALID_APK: /data/app/vmdl99393454.tmp/10_slice__ signatures are inconsistent
Android Studio 在Gradle编译完成后安装APK时总是失败,EventLog提示如下信息: Failed to finalize session : INSTALL_FAILED_IN ...