求助,为什么全是WA
查看原帖
求助,为什么全是WA
433642
m泛函625楼主2021/2/24 17:11
#include<iostream>
#include<cstring>
char str[101] = {0};
using namespace std;
void func1(const char*app)
{
	int len = strlen(str);
	int i = 0;
	while (app[i])
		str[len++] = app[i++];
	str[len] = '\0';
	cout << str<<endl;
};
void func2(int s, int f)
{
	char temp[101] = { 0 };
	int i = 0;
	while (f)
	{
		temp[i++] = str[s++];
		f--;
	}
	memset(str,0,101);
	i = 0; int j = 0;
	while (temp[j])
		str[i++] = temp[j++];
	str[i] = '\0';
	cout << str<<endl;
};
void func3(int a, const char* ins)
{
	char temp[101] = { 0 };
	int i = 0, j = 0;
	while (j < a)
		temp[i++] = str[j++];
	int len = strlen(temp);
	 i = 0;
	while (ins[i])
		temp[len++] = ins[i++];
	temp[len] = '\0';
	len = strlen(temp); i = a;
	while (str[i])
		temp[len++] = str[i++];
	temp[len] = '\0';
	memset(str, 0, 101);
	i = 0;  j = 0;
	while (temp[j])
		str[i++] = temp[j++];
	cout << temp<<endl;
};
bool search(const char* f, const char* s,int pos)
{
	if (!s[pos])return true;
	if (f[pos] == s[pos])
		if(search(f, s, pos+ 1))
			return true;
	return false;
};
int func4(const char* sonstr)
{
	
	int i = 0,pos=0;
	while (str[i])
	{
		if (str[i] == sonstr[pos])
			if (search(str + i, sonstr, 0))
				return i;
			else {
				i += strlen(sonstr);
				continue;
			}

		++i;
	}
	if (str[i])return i;
	return -1;
};
int main()
{
	int opcnt;
	cin >> opcnt;
	cin.get();
	cin.getline(str, 101);
	int mode;
	while (opcnt)
	{
		opcnt--;
		cin >> mode;
		if (mode == 1)
		{
			char app[105];
			cin >> app;
			func1(app);
			continue;
		}
		if (mode == 2)
		{
			int s, f;
			cin >> s >> f;
			func2(s, f);
			continue;
		}
		if (mode == 3)
		{
			int a; char ins[101];
			cin >> a;
			cin.get();
			cin.getline(ins, 101);
			func3(a, ins);
			continue;
		}
		if (mode == 4)
		{
			char sonstr[101];
			cin.get();
			cin.getline(sonstr, 101);
			cout<<func4(sonstr)<<endl;
			continue;
		}
	}
};
2021/2/24 17:11
加载中...