我的代码接受一个字符串,并试图检查是否存在一个输入字符串的排列或不存在。如果存在一个这样的字符串,打印它否则打印“没有答案”。但我的代码doesn' t编译并显示错误。 错误是::没有匹配函数调用'next_permutation(std :: string &)'| 完成此任务的正确方法是什么?next_permutation in C++ on strings
#include <bits/stdc++.h>
using namespace std;
int main(){
int t;
cin>>t;
while(t--){
string s;
cin>>s;
string ans=next_permutation(s);// do permutation and store it in string ans
if(ans==s)// if there is no permutation possible original and ans will be same
cout<<"no answer "<<endl;
else
cout<<ans<<endl;// else print ans
}
}
你读过错误消息了吗?我建议您在发布到stackoverflow之前作为您的第一步。 – user2079303
@ user2079303调用'next_permutation(std :: string&)'时没有匹配函数| –
将相关信息也放入问题中,而不只是在评论中。 – user2079303