各位大佬救救!
查看原帖
各位大佬救救!
1358580
lixintian2014楼主2024/10/2 15:26
#include<bits/stdc++.h>
using namespace std;
string a[1005];
int main()
{
	string s;
	getline(cin, s);
	for(int i = 0; i < s.size(); i ++)
	{
		if (s[i] >= 'A' and s[i] <='Z')
		{
			s[i] = s[i] + 32;
		}
		else if (s[i] >= 'a' and s[i] <= 'z')
		{
			s[i] = s[i] - 32;
		}
	}
	int cnt = 0;
	string f = "";
	for(int i = 0; i < s.size(); i ++)
	{
		if ((s[i] >= 'a' and s[i] <= 'z') or (s[i] >= 'A' and s[i] <= 'Z'))
		{
			f += s[i];
		}
		else if (s[i] == ' ')
		{
			if (s[i] == ' ' and s[i - 1] != ' ')
			{
				a[++ cnt] = f;
				f = "";
			}
		}
		else
		{
			f += s[i];
		}
	}
	a[++ cnt] = f;
	f = "";
	for(int i = cnt; i >= 1; i --)
	{
		cout << a[i] << " ";
	}
	return 0;
}

其他地方都会,不会处理数字

2024/10/2 15:26
加载中...