',subtitle:{text:["Loading..."],hitokoto:{enable:!0,show_author:!0,api:"https://v1.hitokoto.cn"},typing_speed:100,backing_speed:80,starting_delay:500,backing_delay:1500,loop:!1,smart_backspace:!0},text_color:{light:"#434343",dark:"#d1d1b6"},text_style:{title_size:"2.8rem",subtitle_size:"1.5rem",line_height:1.2},custom_font:{enable:!1,family:null,url:null},social_links:{enable:!0,style:"default",links:{github:"https://github.com/FrederickBun",instagram:null,zhihu:"https://www.zhihu.com/people/frederick-asyou",twitter:"https://twitter.com/FrederickAsYou",email:"i@setbun.com",bilibili:"https://space.bilibili.com/689929775?from=buntalk",facebook:"https://www.facebook.com/FrederickAsYou",youtube:"https://www.youtube.com/@Fredgg0017","fa-solid fa-train-subway":"https://www.travellings.cn/go.html","fa-solid fa-bell":"https://follow.it/buntalk?leanpub"},qrs:{weixin:null,"fa-solid fa-circle-dollar-to-slot":"https://cdn.jsdelivr.net/gh/FrederickBun/upyun-rhimgcdn@img/upload/202408110944048.png"}}},plugins:{feed:{enable:!0},aplayer:{enable:!1,type:"fixed",audios:[{name:null,artist:null,url:null,cover:null,lrc:null}]},mermaid:{enable:!0,version:"9.3.0"}},version:"2.7.2",navbar:{auto_hide:!1,color:{left:"#DCE2F1",right:"#FAF9DE",transparency:35},width:{home:"1200px",pages:"1000px"},links:{Home:{path:"/",icon:"fa-solid fa-planet-ringed"},Library:{icon:"fa-solid fa-book-sparkles",submenus:{Timeline:"/archives",Categories:"/categories",Tags:"/tags"}},Services:{icon:"fa-solid fa-server",submenus:{"Uptime status":"https://status.setbun.com/","Count Service":"https://vercount.one/","Whois Search":"https://whois.api.setbun.com/"}},About:{icon:"fa-solid fa-mug-hot",submenus:{Me:"/about",Links:"/links",Essays:"/essays",Photos:"/masonry",Subscribe:"/subscribe",Porfolio:"https://frederication.work"}}},search:{enable:!0,preload:!1}},page_templates:{friends_column:2,tags_style:"blur"},home:{sidebar:{enable:!0,position:"left",first_item:"menu",announcement:'营火,噼啪作响……
',show_on_mobile:!0,links:{Timeline:{path:"/archives",icon:"fa-regular fa-timeline"},Tags:{path:"/tags",icon:"fa-regular fa-tags"},Categories:{path:"/categories",icon:"fa-regular fa-folder-closed"},Essays:{path:"/essays",icon:"fa-regular fa-comment"},Photos:{path:"/masonry",icon:"fa-regular fa-images"},Travelling:{icon:"fa-solid fa-train-subway",path:"https://www.travellings.cn/go.html"},Subscibe:{icon:"fa-solid fa-bell",path:"/subscribe"}}},article_date_format:"auto",excerpt_length:300,categories:{enable:!0,limit:10},tags:{enable:!0,limit:10}},footerStart:"2023/2/6 03:09:13"},window.lang_ago={second:"%s seconds ago",minute:"%s minutes ago",hour:"%s hours ago",day:"%s days ago",week:"%s weeks ago",month:"%s months ago",year:"%s years ago"},window.data={masonry:!0}
题目
1.题目分析
一道简单的字符串操作题,直接套用C++中字符串对应的操作即可
2.做题思路
- 使用
while
循环读入字符串 inpt
为 .
时停止读入- 对
inpt
字符串执行 inpt.append(1,' ')
意思是在读入的字符串后加一个空格,因为 cin
会排掉空格 - 定义一个
str
字符串用来储存答案 - 对
str
字符串执行 str.insert(0, inpt)
即将输入内容添加至 str
字符串最前面
- 输出
str
即可
3.复杂度计算
由于只需要循环长度次,所以时间复杂度为是完全不会超的
4.完整代码
希望大家不要让我强行上反作弊
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| #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; }
|
写在最后
有问题请及时评论,我会做出对应的修改!
- Title: 「题解」 字符串反转
- Author: 磅豆龙
- Created at : 2024-07-02 14:08:15
- Updated at : 2024-07-03 14:11:15
- Link: https://blog.setbun.com/p/20240702.html
- License: This work is licensed under CC BY-NC-SA 4.0.