当前位置:   article > 正文

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

c++价值一个亿的代码

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;
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
#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;
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家小花儿/article/detail/277209
推荐阅读
相关标签
  

闽ICP备14008679号