当前位置:网站首页>3342: String manipulation problem solving
3342: String manipulation problem solving
2022-08-11 01:59:00 【wkh2021】
看到 CSDN The solution to this question is rather lengthy,The simplified code is given here,
这道题是一道不错的 string class function exercises,There are many details to pay attention to
AC code:
#include <iostream>
#include <string>
#include <cstdlib>
#include <sstream>
using namespace std;
#define a_i atoi(get().c_str())
string a[25],get();int n=0;
inline string add(){
string s1=get(),s2=get();
if(s1.size()>5||s2.size()>5)return s1+s2;
int a1=atoi(s1.c_str()),a2=atoi(s2.c_str());
string s3=to_string(a1),s4=to_string(a2);
if(s1==s3&&s2==s4)return to_string(a1+a2);
return s1+s2;
}
inline string copy(){
int x=a_i,pos=a_i,len=a_i;return a[x].substr(pos,len);}
inline string find(){
string s=get();int x=a_i;
return a[x].find(s)==string::npos?to_string((int)s.length()):to_string(a[x].find(s));
}
inline string rfind(){
string s=get();int x=a_i;
return a[x].rfind(s)==string::npos?to_string((int)s.length()):to_string(a[x].rfind(s));
}
inline void insert(){
string s=get();a[a_i].insert(a_i,s);}
inline void reset(){
string s=get();a[a_i]=s;}
inline void print(){
cout<<a[a_i]<<'\n';}
inline void printall(){
for(int i=1;i<=n;i++)cout<<a[i]<<'\n';}
inline string get(){
string s;cin>>s;
if(s=="add")return add();
else if(s=="copy")return copy();
else if(s=="find")return find();
else if(s=="rfind")return rfind();
else if(s=="insert")insert();
else if(s=="reset")reset();
else if(s=="print")print();
else if(s=="printall")printall();
else return s;return "";
}
signed main(){
cin>>n;for(int i=1;i<=n;i++)cin>>a[i];
while(get()!="over");
return 0;
}
边栏推荐
猜你喜欢
Section 4-6 of the first week of the second lesson: Appreciation of medical prognosis cases + homework analysis
FPGA学习专栏-串口通信(xinlinx)
FPGA learning column (xinlinx) serial communication -
通过热透镜聚焦的高斯光束
MySQL - an SQL in MySQL is how to be performed?
Tomca启动闪退问题如何解决
MySQL八股文背诵版(续)
英伟达 GPU 架构简史
21、阿里云oss
How to solve the problem of Tomcat booting and crashing
随机推荐
项目构建工具-Gradle入门
阿里亿级并发册 + 机器学习算法 + 面试册 + 优化册 + 代码册 笔记!!!
从键入网址到网页显示的详细过程
3342:字符串操作 题解
install dlib library
Oops Framework模板项目新手引导
[The method of calling the child page from the parent page of the iframe] Stepping on the pit: It is the key to use `[x]` when getting elements. You cannot use `.eq(x)`, otherwise it will not be obtai
OptiFDTD应用:用于光纤入波导耦合的硅纳米锥仿真
This Thursday evening at 19:00, Lesson 5 of the sixth phase of knowledge empowerment丨OpenHarmony WiFi subsystem
迭代器和生成器
两日总结十一
MySQL Basics [Part 1] | Database Overview and Data Preparation, Common Commands, Viewing Table Structure Steps
备战“金九银十”,软件测试功能 / 数据库 /linux/ 接口 / 自动化 / 测试开发面试真题解析
MySQL八股文背诵版(续)
年薪30W,BAT抢着要,懂面试技巧的测试人究竟多吃香?
最新国产电源厂家及具体型号pin-to-pin替代手册发布
数据的存储(下)——浮点型在内存中的存储
Sigma开发注意细节
TRCX:掺杂过程分析
TRCX: doping process analysis