求助,为什么自己跑过了,提交就全wa
查看原帖
求助,为什么自己跑过了,提交就全wa
502226
cleverC楼主2021/8/22 19:59

大佬们好,为什么我的样例和下载的第一个数据在自己电脑上跑都是正确的,然后提交上去就全是WA啊o(╥﹏╥)o救命

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

int main() {

	int q;
	string a;
	cin >> q >> a;
	while(q--) {
		int k;	// 每次输入的操作
		cin >> k;
		if(k == 1) {
			string temp;
			cin >> temp;
			a += temp;	// 拼接这两个字符串
			cout << a <<endl;
		}
		else if(k == 2) {
			int p,q,i,j;
			cin >> p >> q;
			string temp; // 用temp记录结果
			for(i = p,j = 0;j < q;i++,j++) {
				temp += a[i];
			}
			// cout<< "temp = " << temp << endl;
			a = temp;	// 把temp赋值给a
			cout << a << endl;
		}
		else if (k == 3) {
			int m;
			cin >> m;
			string temp,b;
			cin >>temp;
			for(int i = 0 ;i < m;i++) {	//先拼前半段
				b += a[i];
			}
			b += temp;	// 中间加上
			unsigned int i;
			for(i = m;i < a.length();i++) {	// 再拼后半段
				b += a[i];
			}
			a = b;
			cout << a << endl;
		}
		else {
			string find;
			cin >> find;
			int ans = -1;
			unsigned int i;
			for(i = 0;i < a.length() - find.length()+1;i++) {
				unsigned int j = 0,k = i;
				while(a[k] == find[k] && j < find.length()) {  //如果找到了相同的
					k++;
					j++;
				}
				if(j == find.length()) {
					// cout << "i="<<i<<"  j="<<j<<endl;
					ans = i;
					break;
				}
			}
			cout << ans << endl; 
		}
	}
	return 0;
}
2021/8/22 19:59
加载中...