当前位置:网站首页>L1-064 AI core code valued at 100 million
L1-064 AI core code valued at 100 million
2022-07-24 11:41:00 【Cod_ ing】
A simple simulation problem , Compare and test the application of some methods , If you can't make good use of it “ wheel ” In fact, it will take a lot of time in the game , Do more harm than good !
1、 It is suggested to establish a mapping relationship , Easy to find and replace
2、 Use STL In the container “string” Type of replace Member functions
3、 The parts with single function and frequent calls are replaced by sub functions
#include<iostream>
#include<string>
#include<map>
using namespace std;
bool is(char ch) {
// Judge whether it is a symbol
if (ch >= 'A' && ch <= 'Z') return false;
if (ch >= 'a' && ch <= 'z') return false;
if (ch >= '0' && ch <= '9') return false;
return true;
}
bool ok(string s,int len, int pos) {
// Judge whether the word is independent
if (pos > 0) {
if (is(s[pos - 1]) && is(s[pos + len]))
return true;
}
else if (is(s[pos + len])) return true;
return false;
}
int main() {
int N;
string s1, s2;
string M[4][2] = {
// Establish a mapping relationship , It can effectively reduce the amount of code
{
"can you","& can"},{
"could you","& could"},{
"I","you"},{
"me","you"}
};
cin >> N;
cin.get();
while (N--) {
getline(cin, s1);
s2 = s1;
while (s2[0] == ' ') s2.erase(s2.begin()); // Delete the beginning of the line 、 Space at the end of line
while (s2[s2.size() - 1] == ' ') s2.erase(s2.end()-1);
for (int i = 0; i < s2.size(); i++) {
// Delete extra spaces between words and symbols
if (s2[i] == ' ') {
while (s2[i + 1] == ' ') s2.erase(i + 1, 1);
if (is(s2[i + 1])) {
s2.erase(i, 1);
i--;
}
}
}
for (int i = 0; i < s2.size(); i++) {
// Replace caps and question marks
if (s2[i] >= 'A' && s2[i] <= 'Z' && s2[i] != 'I') s2[i] = s2[i] - 'A' + 'a';
if (s2[i] == '?') s2[i] = '!';
}
for (int i = 0; i < s2.size(); i++) {
// Replace some words , Be careful could I and can I Medium “I” It should not be replaced by “you”
for (int j = 0; j < 4; j++) {
if (s2.substr(i, M[j][0].size()) == M[j][0] && ok(s2, M[j][0].size(), i)) s2.replace(i, M[j][0].size(), M[j][1]);
}
}
for (int i = 0; i < s2.size(); i++) {
if (s2[i] == '&') s2[i] = 'I';
}
cout << s1 << endl;
cout << "AI: " << s2 << endl;
}
return 0;
}
边栏推荐
- IT圈中的Bug的类型与历史
- 有关并行的两个重要定律
- iMeta观点 | 短读长扩增子测序是否适用于微生物组功能的预测?
- DevOps及DevOps常用的工具介绍
- Experience of redis deepwater area -- Interview reference
- tcp 服务端接收数据处理思路梳理,以及select: Invalid argument报错 笔记
- Mysql database
- Jackson parsing JSON detailed tutorial
- The difference between YPbPr and YCbCr
- Hash - 15. Sum of three numbers
猜你喜欢

【Markdown语法高级】让你的博客更精彩(四:设置字体样式以及颜色对照表)

Is there any charge for PDF processing? impossible!

The art of management - driving software R & D efficiency through leadership

HCIP MGRE实验 第三天

One week's wonderful content sharing (issue 13)

Share the typora tool

【反序列化漏洞-01】序列化与反序列化简介

使用Prometheus+Grafana实时监控服务器性能
![08 [AIO programming]](/img/a6/156cb97e653190c76f22c88b758fef.png)
08 [AIO programming]

Use prometheus+grafana to monitor server performance in real time
随机推荐
High frequency written test questions (Weilai)
Performance test summary (I) -- basic theory
Repeated calls, messages, idempotent schemes, full collation
哈希——15. 三数之和
Leetcode 257. 二叉树的所有路径
L1-049 天梯赛座位分配
[TA frost wolf umay - "hundred people plan] Figure 3.3 surface subdivision and geometric shader large-scale grass rendering
Basic syntax of MySQL DDL and DML and DQL
2 万字详解,吃透 ES!
The third day of hcip mGRE experiment
Dry goods sharing - taking over a new data team as a lead - Problem Inventory and insights findings
Semaphore details
黑马瑞吉外卖之员工信息分页查询
MOS tube - Notes on rapid recovery application (I) [principle]
Shengxin weekly issue 37
使用Prometheus+Grafana实时监控服务器性能
Hash - 1. Sum of two numbers - some people fall in love during the day, some people watch the sea at night, and some people can't do the first question
Sentinel vs Hystrix 限流对比,到底怎么选?
Fastcgi operation principle and PHP FPM parameter configuration
C#入门系列(二十九) -- 预处理命令