求助各位大神!!!为什么我只有#5WA
查看原帖
求助各位大神!!!为什么我只有#5WA
919543
shaddy楼主2023/1/23 17:19
#include<iostream>
#include<string>
#include<cstring>

using namespace std;

char s1[10001], s2[10001], s3[10001], s4[10001];
int main()
{
	int n, num, a, b;
	cin >> n >> s1;

	for (int i = 0; i < n; ++i)
	{
		cin >> num;

			if (num == 1)
			{
				for(int i=0;i<10000;++i)
                {
                    s2[i]='\0';
                }
                
				cin >> s2;
				strcat(s1, s2);
				cout << s1 << endl;
			}

			if (num == 2)
			{
				cin >> a >> b;
				
                for(int i=0;i<10000;++i)
                {
                    s2[i]='\0';
                }

				if (static_cast<int>(strlen(s1)) < a + b)
				{
					b = static_cast<int>(strlen(s1)) - a;
				}

				for (int j = 0; j < b; ++j)
				{
					s2[j] = s1[j + a];
				}

				for(int i=0;i<10000;++i)
                {
                    s1[i]='\0';
                }
				strcpy(s1, s2);
				cout << s1 << endl;
			}

			if (num == 3)
			{
				for(int i=0;i<10000;++i)
                {
                    s2[i]='\0';
                }
                
				cin >> a;
				cin >> s2;
				int x = static_cast<int>(strlen(s1));
				for (int j = a; j <= static_cast<int>(strlen(s1)); ++j)
				{
					s4[j - a] = s1[j];
				}
				for (int j = 0; j < static_cast<int>(strlen(s2)); ++j)
				{
					s1[a + j] = s2[j];
				}
				for (int j = 0; j < static_cast<int>(strlen(s4)); ++j)
				{
					s1[j + a + static_cast<int>(strlen(s2))] = s4[j];
				}
				for (int j = 0; j < x + static_cast<int>(strlen(s2)); ++j)
				{
					cout << s1[j];
				}
				cout << endl;
			}

			if (num == 4)
			{
				for(int i=0;i<10000;++i)
                {
                    s2[i]='\0';
                }

				cin >> s2;
				int flag = 0;

				for (int j = 0; j < static_cast<int>(strlen(s1)); ++j)
				{
					if (s1[j] == s2[0])
					{
						for (int k = 1; k < static_cast<int>(strlen(s2)); ++k)
						{
							if (s1[j + k] == s2[k])
								flag = 1;
							else
							{
								flag = 0;
								break;
							}
						}
						if (flag)
						{
							cout << j;
							break;
						}
					}
					if (j == static_cast<int>(strlen(s1)) - 1 && flag == 0)
					{
						cout << "-1";
					}
				}
				cout << endl;
			}
		
	}

	return 0;
}

请问这段代码哪里有问题?

2023/1/23 17:19
加载中...