文章

60

粉丝

361

获赞

41

访问

499.1k

头像
字符串函数真香
P1387 北京邮电大学
发布于2021年1月15日 16:05
阅读数 10.9k

#include <bits/stdc++.h>
using namespace std;

int main()
{
	int n;
	string s;
	while(cin>>s)
	{
		cin>>n;
		for(int i=0;i<n;i++)
		{
			string caozuo;
			cin>>caozuo;
			int begin=caozuo[1]-'0',len=caozuo[2]-'0';
			if(caozuo[0]=='0')
			{
				for(int i=begin;i<begin+len/2;i++)//翻转
				{
					char temp=s[i];
					s[i]=s[len-1-i+2*begin];
					s[len-1-i+2*begin]=temp;
				}
			}
			else if(caozuo[0]=='1')//替换
			{
				string rep=caozuo.substr(3,caozuo.size()-3);
				s=s.replace(begin,len,rep);
			}
			cout<<s<<endl;
		}
	}
	//system("pause");
	return 0;
}

 

登录查看完整内容


登录后发布评论

2 条评论
James
2021年1月27日 11:28

这个字符串不是最大100个吗  这样做不是默认起始坐标和操作长度只能是个位数吗

赞(1)

老猫 : 回复 James: 请认真读题!

2021年2月2日 11:04