当前位置:网站首页>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 !
边栏推荐
猜你喜欢

Win10 tips (1) -- transfer desktop location

浅谈基本的网络基本故障和问题排查

200行代码快速入门文档型数据库MonogoDB

MySQL学习笔记(2)——存储过程与存储函数

2022备战秋招10W字面试小抄pdf版,附操作系统、计算机网络面试题

IDEA成功连接Database但不显示表怎么办

搭建阿里云+typora+Picgo图床错误分析

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

ES6学习笔记(1)——快速入门

There is a problem with the time zone when the idea connects to the database. The server returns invalid timezone is red Need to set ‘serverTimezone‘ property.
随机推荐
JS common utils encapsulation
There is another example of repeater
Unity learning notes (rigid body physics collider trigger)
Win10 tips (1) -- transfer desktop location
"Testing novice encyclopedia" 5-minute quick start pytest automated testing framework
Greedy method, matroid and submodular function (refer)
v-if,v-else,v-for
idea优化小攻略
用Matlab生成适用于期刊及会议的图形- plot
2022 Ningde Vocational College Teachers' practical teaching ability improvement training - network construction and management
新系统安装MySQL+SQLyog
mysql学习笔记(1)——变量
Kinect for unity3d - backgroundremovaldemo learning
JMeter interface automation - how to solve the content type conflict of request headers
Self control principle learning notes - system stability analysis (1) - BIBO stability and Routh criterion
Some advice for NS2 beginner.
Using functions to extract numbers from text strings in Excel
Opening and using Alibaba cloud object storage OSS
kettle EXCEL 累计输出数据
Learning notes of Microcomputer Principles - common addressing methods