当前位置:网站首页>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 !
边栏推荐
- Matrix of shell programming -- it's cute and cool
- Summary of "performance test" of special test
- Unity显示Kinect捕获的镜头
- Electromagnetic field learning notes - vector analysis and field theory foundation
- How to generate random numbers with standard distribution or Gaussian distribution
- 编程式跳转
- Unity display Kinect depth data
- [Luogu p4183] cow at large P (graph theory) (tree array)
- Resource for NS2 beginner
- WORD 2007+使用技巧
猜你喜欢
随机推荐
kettle switch / case 控件实现分类处理
自控原理学习笔记-系统稳定性分析(2)-环路分析及Nyquist-Bode判据
Nacos的基本使用(1)——入门
X-shell remote connection virtual machine
How to break the team with automated testing
kettle 分列、合并记录
v-if,v-else,v-for
Useful resources for ns2
Usage of ref keyword
Greedy method, matroid and submodular function (refer)
Study notes of Microcomputer Principles - general integer instructions and Applications
Kinect for Unity3d----KinectManager
ES6 new method
Kinect2 for Unity3D——AvatarDemo学习
Using MATLAB to generate graphics for journals and conferences - plot
SSM integration
win10小技巧(1)——转移桌面位置
kettle学习——8.2版本的资源库配置变为灰色,且没有了Connect按钮
Down sampling - signal phase and aliasing
Opening and using Alibaba cloud object storage OSS








