当前位置:网站首页>Daily question (02): inverted string
Daily question (02): inverted string
2022-07-27 19:19:00 【Liu jingyiru】

Learning enlightenment :
1. First of all, this is an operation problem . The initial and final states are known . So consider “ Template mapping ”.
2. Basic skill : Skilled double-layer cycle operation + Write the beginning and end conditions
3. Practice makes perfect :auto Keyword application , Constantly assign values automatically +(C++STL The application of the library )
4. Template mapping ---》 Data can be divided into letters , Numbers , Space ..... etc. . Data range can be changed ( For limiting letters ACII To judge ) Different settings of inverted format .
5.” Thinking problems “---》 A little recursive . If you don't analyze the fact that falling twice is equal to yourself (a And b XOR twice equals b,,, Sometimes ideas are abstract , It also depends on the inspiration at that time ), You won't think of encapsulating words into one and then inverting , It may be reversed by traversing letters one by one , It's going to be a mess . The more boundary judgments , The more you use it, the easier it is to make mistakes . Cycle time , It means that it may bring O(n) Complexity , So be flexible and consider simplification .
6.STL Libraries are essentially data structures , Handle string and linked list problems , Draw on ideas and analytical methods , The basic skills of cooperating with circulation and writing judgment conditions . On the other side, we need help STL Traversal of Library , Simplified steps .
Even if there are many boundaries , Step by step , It's not easy to make a mistake
Pseudo code
1. I / O format , Header file , Complete variable initialization
2. Global inversion
3. Word inversion
Retrieve each word , Reverse a word once ,
Inverse condition of each word : Right border (s.end) Space encountered
4. Dealing with boundaries , String to /0 ending . Marks the end of retrieval and inversion #include<iostream>
#include<algorithm>
using namespace std;
int main()
{
string s;
getline(cin, s);
// Flip the whole sentence
reverse(s.begin(), s.end());
// Flip Words
auto start = s.begin();
while (start != s.end())
{
auto end = start;
while (start != s.end() && *end != ' ')
end++;
reverse(start, end);
if (end != s.end())
start = end + 1;
else
start = end;
}
cout<< s << endl;
return 0;
}Limited by knowledge , Just make a summary of the current basic learning , Ideas and knowledge are still insufficient , Please correct me if there is any mistake !
边栏推荐
猜你喜欢

mysql学习笔记(1)——变量

kettle8.2 安装及常见问题

SSM integration

Win10 tips (1) -- transfer desktop location

Unity learning notes (rigid body physics collider trigger)

v-if,v-else,v-for

I'm afraid I won't use the JMeter interface testing tool if I accept this practical case

2022 preparation for autumn recruitment 10W word interview sketch PDF version, with operating system and computer network interview questions

kettle引用外部脚本完成电话号码清洗、去重缩进

Unity shows Kinect captured shots
随机推荐
PHP string operation
Nacos基本概念和单机部署
电磁场学习笔记-矢量分析和场论基础
IDEA连接数据库时区问题,报红Server returns invalid timezone. Need to set ‘serverTimezone‘ property.
Useful resources for ns2
浅谈基本的网络基本故障和问题排查
asp.net 的经验
微机原理学习笔记-通用整数指令及应用
kettle 合并记录 数据减少
mysql学习笔记(1)——变量
Code interview of Amazon
Unity-显示Kinect深度数据
PHP字符串操作
Webmagic+selenium+chromedriver+jdbc垂直抓取数据。
新系统安装MySQL+SQLyog
大冤种们,新进测试行业,如何正确选择意向企业?
Greedy method, matroid and submodular function (refer)
又有一个Repeater的例子
Win10 tips (1) -- transfer desktop location
Kinect for Unity3d----KinectManager