L1-064 估值一亿的AI核心代码 (20分)
#include <bits/stdc++.h>
#define int ll
using namespace std;
typedef long long ll;
const int maxn=1e5+10;
void solve() {
string str[1005];
int cnt=0;
string s;
getline(cin,s);
cout<<s<<"\n"<<"AI:";
for (int i = 0; i < s.size(); ++i) {
if (isupper(s[i])&&s[i]!='I') s[i]=tolower(s[i]);
else if (!isalnum(s[i])) s.insert(i," "),i++;
if (s[i]=='?') s[i]='!';
}
stringstream ss(s);
while (ss>>s) str[cnt++]=s;
if (!isalnum(str[0][0])) cout<<" ";
for (int i = 0; i < cnt; ++i) {
if (!isalnum(str[i][0])) cout<<str[i];
else if ((str[i]=="can"||str[i]=="could")&&str[i+1]=="you")cout << " I " << str[i],i++;
else if (str[i]=="I"||str[i]=="me") cout << " you";
else cout << " " << str[i];
}
cout<<"\n";
}
signed main() {
int _ = 1;
cin >> _;getchar();
while (_--) {
solve();
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
cin.get();
while (n--) {
string s;
getline(cin, s);
cout << s << endl;
for (char & c : s) {
if (c >='A' && c <= 'Z' && c != 'I') {
c = c - 'A' + 'a';
}
}
s = regex_replace(s, regex(" +"), " ");
s = regex_replace(s, regex("^ | $"), "");
s = regex_replace(s, regex(" (\\W)"), "$1");
s = regex_replace(s, regex("\\?"), "!");
s = regex_replace(s, regex("\\bcan you\\b"), "A");
s = regex_replace(s, regex("\\bcould you\\b"), "B");
s = regex_replace(s, regex("\\b(I|me)\\b"), "C");
s = regex_replace(s, regex("A"), "I can");
s = regex_replace(s, regex("B"), "I could");
s = regex_replace(s, regex("C"), "you");
cout << "AI: " << s << endl;
}
return 0;
}
转载请注明原文地址:https://blackberry.8miu.com/read-35551.html