PTA 5-31 字符串循环左移
2016-05-14 20:09
211 查看
输入一个字符串和一个非负整数NNN,要求将字符串循环左移NNN次。
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
using namespace std;
const int N=105;
char s
;
int main()
{
gets(s);
int n,len=strlen(s),i,j,k;
cin>>n;
char tmp;
for(i=1;i<=n;++i)//times
{
tmp=s[0];
for(j=1;j<=len-1;++j)
{
s[j-1]=s[j];
}
s[len-1]=tmp;
}
for(i=0;i<len;++i)
cout<<s[i];
}
输入格式:
输入在第1行中给出一个不超过100个字符长度的、以回车结束的非空字符串;第2行给出非负整数NNN。输出格式:
在一行中输出循环左移NNN次后的字符串。输入样例:
Hello World! 2
输出样例:
llo World!He
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
using namespace std;
const int N=105;
char s
;
int main()
{
gets(s);
int n,len=strlen(s),i,j,k;
cin>>n;
char tmp;
for(i=1;i<=n;++i)//times
{
tmp=s[0];
for(j=1;j<=len-1;++j)
{
s[j-1]=s[j];
}
s[len-1]=tmp;
}
for(i=0;i<len;++i)
cout<<s[i];
}
相关文章推荐
- PAT B 1018. 锤子剪刀布
- MAVEN报错:Missing artifact com.sun:tools:jar:1.5.0:system
- 互联网思维对人性一面的利用
- 1087. All Roads Lead to Rome (30)【最短路】——PAT (Advanced Level) Practise
- Java个别关键字
- 2016"百度之星" - 资格赛(Astar Round1)Problem D(排序+map)
- 数据结构_静态链表_哈夫曼
- ReentrantLock解析,lock与unlock方法分析
- 数量经济学推荐的Julia教程
- JavaWeb学习笔记——Ajax
- MySQL学习笔记--视图的创建,删除,修改,算法
- 灰帽子python 学习记录 3
- R中的<-和=赋值符号的细致区别
- 作业八—三角形判断单元测试体会
- java设计模式之结构型模式-代理模式
- 旋转数组找最小值
- N+1 select problem
- 回文词
- 169. Majority Element [easy] (Python)
- 研究音频编解码要看什么书