超小声:题目这么模糊肯定是为了提高区分度吧doge
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <regex>
using namespace std;
#define fo(i, n) for (int i = 1; i <= n; ++i)
void solve()
{
//ofstream cout("output.txt");
int n;cin >> n;getchar();
while (n--)
{
string s;
getline(cin, s);
cout << s << '\n';
regex format(R"(^\s+)");
s = regex_replace(s, format, "");
format=(R"(\s+$)");
s = regex_replace(s, format, "");
format = (R"(\b\s+\b)");
s = regex_replace(s, format, " ");
format = (R"((\s+)([[:punct:]]))");
s = regex_replace(s, format, "$2");
format = (R"(([[:punct:]])(\s+))");
s = regex_replace(s, format, "$1 ");
transform(s.begin(), s.end(), s.begin(), [](unsigned char c) {
if (c != 'I' && isupper(c))
return tolower(c);
else
return (int)c;
});
format = (R"(\bI\b)");
s = regex_replace(s, format, "YOU");
format = (R"(\bme\b)");
s = regex_replace(s, format, "YOU");
format = (R"(\bcan you\b)");
s=regex_replace(s, format, "I can");
format = (R"(\bcould you\b)");
s=regex_replace(s, format, "I could");
format = (R"(\?)");
s=regex_replace(s, format, "!");
format = (R"(\bYOU\b)");
s = regex_replace(s, format, "you");
format = (R"(\bYOU\b)");
s = regex_replace(s, format, "you");
cout <<"AI: "+s << '\n';
}
}
int main()
{
solve();
return 0;
}
第一次用的C(太麻烦了nuisance),第二次刷STR时简直无脑regex(Regular Expression 正则表达式)简单高级好用。
练习正则表达式的WebSite
test 2
好比我们去写英文,标点后如果是word,那么该标点与字间要有一个space. i.s
hello , , the better world -> hello,, the better world
test 5
句尾space (一开始忘了......)
Man, What can I say ??? 上面的zero是因为忘了改输入方向........