当前位置:网站首页>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;
}
边栏推荐
- How to go from functional testing to automated testing?
- 07 [use of path and files classes]
- Performance test summary (I) -- basic theory
- 08 [AIO programming]
- Robot framework official tutorial (I) getting started
- tcp 服务端接收数据处理思路梳理,以及select: Invalid argument报错 笔记
- Sorting out the ideas of data processing received by TCP server, and the note of select: invalid argument error
- 栈顶与栈底
- String -- 344. Reverse string
- Hash - 18. Sum of four numbers
猜你喜欢

DevOps及DevOps常用的工具介绍

Two important laws about parallelism

Robot framework official tutorial (I) getting started

链表——142. 环形链表 II

使用Prometheus+Grafana实时监控服务器性能
What is cloud native? Why is cloud native technology so popular?

HCIP MGRE实验 第三天

Talk about software testing - automated testing framework
![[deserialization vulnerability-01] Introduction to serialization and deserialization](/img/e4/6b9ee6ee74f3cdc3c886ed3af9ef73.png)
[deserialization vulnerability-01] Introduction to serialization and deserialization

Sorting out the ideas of data processing received by TCP server, and the note of select: invalid argument error
随机推荐
Shell script
MySql的DDL和DML和DQL的基本语法
Idea runs the wordcount program (detailed steps)
Paging query of employee information of black maredge takeout
The third day of hcip mGRE experiment
Robot framework official tutorial (I) getting started
6k+ star, a deep learning code base for Xiaobai! One line of code implements all attention mechanisms!
使用Prometheus+Grafana实时监控服务器性能
Hcip OSPF interface network type experiment day 4
Directional crawling Taobao product name and price (teacher Songtian)
L1-059 敲笨钟
【反序列化漏洞-02】PHP反序列化漏洞原理测试及魔术方法总结
L1-049 天梯赛座位分配
A*与JPS
How to choose sentinel vs. hystrix current limiting?
Nodejs ctf 基础
字符串——剑指 Offer 05. 替换空格
How to access the code of online customer service system to your website
tcp 服务端接收数据处理思路梳理,以及select: Invalid argument报错 笔记
MySQL creates partition tables and automatically partitions them by day