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

推荐订阅源

The Cloudflare Blog
阮一峰的网络日志
阮一峰的网络日志
Martin Fowler
Martin Fowler
D
DataBreaches.Net
The GitHub Blog
The GitHub Blog
人人都是产品经理
人人都是产品经理
V
V2EX
爱范儿
爱范儿
PCI Perspectives
PCI Perspectives
T
Troy Hunt's Blog
Stack Overflow Blog
Stack Overflow Blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
SecWiki News
SecWiki News
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
The Hacker News
The Hacker News
小众软件
小众软件
雷峰网
雷峰网
D
Docker
NISL@THU
NISL@THU
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
腾讯CDC
B
Blog RSS Feed
C
CERT Recently Published Vulnerability Notes
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
U
Unit 42
有赞技术团队
有赞技术团队
P
Palo Alto Networks Blog
G
GRAHAM CLULEY
T
The Exploit Database - CXSecurity.com
T
Tailwind CSS Blog
S
Security @ Cisco Blogs
量子位
I
InfoQ
Application and Cybersecurity Blog
Application and Cybersecurity Blog
大猫的无限游戏
大猫的无限游戏
Schneier on Security
Schneier on Security
Help Net Security
Help Net Security
Latest news
Latest news
The Register - Security
The Register - Security
S
Securelist
W
WeLiveSecurity
A
Arctic Wolf
Security Latest
Security Latest
AWS News Blog
AWS News Blog
L
LINUX DO - 热门话题
S
Secure Thoughts
T
Tenable Blog
Know Your Adversary
Know Your Adversary
月光博客
月光博客
M
MIT News - Artificial intelligence

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;
}

写在最后

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