惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

L
LINUX DO - 最新话题
MyScale Blog
MyScale Blog
月光博客
月光博客
S
SegmentFault 最新的问题
C
CERT Recently Published Vulnerability Notes
P
Proofpoint News Feed
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
人人都是产品经理
人人都是产品经理
K
Kaspersky official blog
Forbes - Security
Forbes - Security
宝玉的分享
宝玉的分享
爱范儿
爱范儿
V
Visual Studio Blog
博客园 - 聂微东
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
N
News and Events Feed by Topic
阮一峰的网络日志
阮一峰的网络日志
V
V2EX
The Cloudflare Blog
Attack and Defense Labs
Attack and Defense Labs
美团技术团队
L
LangChain Blog
NISL@THU
NISL@THU
IT之家
IT之家
T
Tor Project blog
云风的 BLOG
云风的 BLOG
Security Latest
Security Latest
Apple Machine Learning Research
Apple Machine Learning Research
Cisco Talos Blog
Cisco Talos Blog
I
InfoQ
Help Net Security
Help Net Security
Engineering at Meta
Engineering at Meta
Know Your Adversary
Know Your Adversary
I
Intezer
Recent Commits to openclaw:main
Recent Commits to openclaw:main
TaoSecurity Blog
TaoSecurity Blog
P
Palo Alto Networks Blog
GbyAI
GbyAI
Last Week in AI
Last Week in AI
T
Threat Research - Cisco Blogs
T
The Exploit Database - CXSecurity.com
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
博客园 - Franky
L
Lohrmann on Cybersecurity
The Register - Security
The Register - Security
W
WeLiveSecurity
Recorded Future
Recorded Future
大猫的无限游戏
大猫的无限游戏
AWS News Blog
AWS News Blog
G
GRAHAM CLULEY

Frederick's Blog

通过 1Panel 部署 Astro 站点到服务器——公开仓库篇 | Frederick's Blog 用违背道德的行为,抨击合理的事实? | Frederick's Blog 博客三周年:缝缝补补的过去 | Frederick's Blog 观纪录片《苏轼》(下) | Frederick's Blog 观纪录片《苏轼》(上) | Frederick's Blog 《南京照相馆》:在战争的废墟上,显影人性的底片 | Frederick's Blog 观影 |《南京照相馆》 | Frederick's Blog Windows 7 终端开启右键粘贴 | Frederick's Blog 算法竞赛:为什么要写总结? | Frederick's Blog OI 赛制的实用工具 | Frederick's Blog 算法竞赛:拥有一个顺手的 IDE · Windows 篇 | Frederick's Blog 博客两周年,换框架? | Frederick's Blog 数据备份太重要了 | Frederick's Blog WeChat(微信国际服务)与微信(国内服务)的《隐私协议》的天壤之别(其中最让人愤怒的) | Frederick's Blog 题解 | 素数环 | Frederick's Blog Codesign:高效设计的秘诀 | Frederick's Blog Github:设置两步验证(2FA) | Frederick's Blog
题解 | 字符串反转 | Frederick's Blog
2024-07-02 · via Frederick's Blog

题解 | 字符串反转

一道简单的字符串操作题的解题思路

2024年7月2日

题目

题目

1.题目分析

一道简单的字符串操作题,直接套用C++中字符串对应的操作即可

2.做题思路

  • 使用 while 循环读入字符串 inpt . 时停止读入

  • inpt 字符串执行 inpt.append(1,' ') 意思是在读入的字符串后加一个空格,因为 cin 会排掉空格

  • 定义一个 str 字符串用来储存答案

  • str 字符串执行 str.insert(0, inpt) 即将输入内容添加至 str 字符串最前面

  • 输出 str 即可

3.复杂度计算

由于只需要循环长度次,所以时间复杂度为 $O(n)$ 是完全不会超的

4.完整代码

#include <bits/stdc++.h>
using namespace std;

int main()
{
	string str;
	string inpt;
	while(true)
	{
		cin >> inpt ;
		if(inpt == ".")
		{
			break;
		}
		inpt.append(1, ' ');
		str.insert(0, inpt);
	}
	cout << str ;
	return 0;
}

写在最后

有问题请及时评论,我会做出对应的修改!