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

推荐订阅源

博客园_首页
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Know Your Adversary
Know Your Adversary
Latest news
Latest news
H
Help Net Security
C
CERT Recently Published Vulnerability Notes
阮一峰的网络日志
阮一峰的网络日志
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
C
Cyber Attacks, Cyber Crime and Cyber Security
Security Latest
Security Latest
B
Blog RSS Feed
V
Vulnerabilities – Threatpost
T
Threatpost
量子位
P
Proofpoint News Feed
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Cisco Talos Blog
Cisco Talos Blog
F
Fortinet All Blogs
Cyberwarzone
Cyberwarzone
Recorded Future
Recorded Future
博客园 - 聂微东
博客园 - 叶小钗
云风的 BLOG
云风的 BLOG
Forbes - Security
Forbes - Security
H
Hackread – Cybersecurity News, Data Breaches, AI and More
小众软件
小众软件
N
Netflix TechBlog - Medium
aimingoo的专栏
aimingoo的专栏
酷 壳 – CoolShell
酷 壳 – CoolShell
I
InfoQ
Last Week in AI
Last Week in AI
N
News and Events Feed by Topic
Google DeepMind News
Google DeepMind News
宝玉的分享
宝玉的分享
Hugging Face - Blog
Hugging Face - Blog
PCI Perspectives
PCI Perspectives
T
Tenable Blog
C
Cybersecurity and Infrastructure Security Agency CISA
L
LangChain Blog
SecWiki News
SecWiki News
H
Hacker News: Front Page
WordPress大学
WordPress大学
www.infosecurity-magazine.com
www.infosecurity-magazine.com
S
Schneier on Security
H
Heimdal Security Blog
Hacker News - Newest:
Hacker News - Newest: "LLM"
博客园 - 【当耐特】
A
About on SuperTechFans
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
T
Tailwind CSS Blog

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

写在最后

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