当前位置:网站首页>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;
}
边栏推荐
猜你喜欢
随机推荐
sql 使用到where和groupby时建立索引结果为啥是这样,原理是什么?
如何开展性能测试,你知道吗?
Lianshengde W801 series 5-WeChat applet and W801 Bluetooth communication routine (read notes)
两日总结十
【PHP】入门知识
两日总结九
15 DOM 扩展
【开源】壁纸软件,给自己电脑设计专属特效
async和await的理解和用法
Data Analysis Interview Manual "SQL"
【oops-framework】模板项目【oops-game-kit】使用简介
基于 HPSO 与多核 LSSVM 的网络入侵检测
软件测试面试题:软件测试的过程的V模型,说出它的缺点?
install dlib library
WeChat public account background management
C# WebBrower1控件可编辑模式保存时会提示“该文档已被修改,是否保存修改结果”
软件测试面试题:验收测试包括哪三种类型?
Lianshengde W801 series 6-Analyze the Bluetooth communication source code of W801 from the perspective of WeChat applet (indicate method)
Flink二阶段提交
Pytorch/TensorFlow/Numpy常用函数汇总



![Deep Learning [Chapter 2]](/img/09/5eb16731c3c47965da131c2aa0c2c3.png)





