心动提前批第一题 本地AC,求大佬指点哪里出错
#include <iostream> #include <vector> #include <algorithm> #include <string> #include <sstream> #include <list> using namespace std; bool Compare(string &S,string &a,string &b) { bool flag = false; int i = 0; int Number = min(a.size(),b.size()); for(i; i < Number;i++) { if(S.find(a[i]) > S.find(b[i])) { flag = true; break; } } if(i == Number) flag = false; return flag; } void customString(string &S, vector<string> &strV) { for(int i = 0; i < strV.size();i++) { for(int j = 0 ; j < strV.size() - i -1;j++) { if(Compare(S,strV[j],strV[j+1])) { string index = strV[j]; strV[j] = strV[j+1]; strV[j+1] = index; } } } } int main() { string str; getline(cin,str); int N = 0; cin>>N; getchar(); vector<string> strV(N); for(int i = 0; i < N;i++) { string Temp; getline(cin,Temp); strV[i] = Temp; } customString(str,strV); for(auto x : strV) { cout<<x<<endl; } return 0; }
思路是先存放S字符串,然后使用自定义函数查找每个字符串从第一个开始的字符在S的位置,用.find()函数,本地测试三个用例没问题,但是编译器直接case 0%。
求解
#笔试题目##心动网络#