L1-064 估值一亿的AI核心代码 (20分)

3 篇文章 0 订阅

L1-064 估值一亿的AI核心代码 (20分)

#include <bits/stdc++.h>

#define int ll
//#pragma GCC optimize(2)
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() {
    //ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    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");//转换can you
        s = regex_replace(s, regex("\\bcould you\\b"), "B");//转换could you
        s = regex_replace(s, regex("\\b(I|me)\\b"), "C");//转换I、me
 
        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;
}
  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值