PTA|ZJU 估值一亿的AI核心代码 简洁 test point 2 5 C/C++

  超小声:题目这么模糊肯定是为了提高区分度吧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 正则表达式)简单高级好用。

https://regexr.com/

练习正则表达式的WebSite

test 2

好比我们去写英文,标点后如果是word,那么该标点与字间要有一个space. i.s 

hello       ,         ,        the better world -> hello,, the better world

test 5

句尾space  (一开始忘了......)

Man, What can I say ??? 上面的zero是因为忘了改输入方向........

  • 6
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值