【发布时间】:2020-12-27 03:39:49
【问题描述】:
对于这样的字符串输入——“i.like.this.program.very.much”,输出应该是“much.very.program.this.like.i”。
这是我的代码 -
void func(string s,int n){
vector<string>v;
string temp="";
for(int j=0;j<n;j++){
if(s[j]!='.'){
temp+=s[j];
}
else{
v.push_back(temp);
temp="";
}
}
reverse(v.begin(),v.end());
for(int i=0;i<v.size();i++){
cout<<v[i]<<".";
}
cout<<"\n";
}
这里的'n'是字符串长度,'s'是字符串。我得到的输出是 - “very.program.this.like.i.”
【问题讨论】:
-
请提取并提供minimal reproducible example,包括算法未给出预期结果的最短输入(硬编码,而不是通过标准输入)。此外,使用调试器单步执行代码,您可能会自己识别错误。作为这里的新用户,也可以使用tour 并阅读How to Ask。