Hi, can anyone help me figure out why the system test gives a different answer to my computer for this code?. Codeforces Round #425 (Div. 2), Problem B.
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
using namespace std;
bool vali(string test, string s, int alf[300]){
int j = 0, i = 0;
if((int)s.size() == (int)test.size() + 1)
for(; j < (int)s.size(); j++){
if(s[j] == '*'){ continue;}
else if((s[j] == test[i]) || (s[j] == '?' && alf[(int)test[i]] == 1) ){
i++;
continue;
}
else
return false;
}
else if((int)s.size() == (int)test.size()){
for(; j < (int)s.size(); j++){
if(s[j] == '*'){ i++; continue;}
else if((s[j] == test[i]) || (s[j] == '?' && alf[(int)test[i]] == 1) ){
i++;
continue;
}
else
return false;
}
}
if(i == (int)test.size() && j == (int)s.size()) return true;
return false;
}
int main(){
string cad; cin>>cad;
int alf[300];
for(int i = 0; i < (int)cad.size(); i++) alf[i] = 0;
for(int i = 0; i < (int)cad.size(); i++)
alf[(int)cad[i]]++;
string s; cin>>s;
int n; cin>>n;
string test;
bool flag = true;
vector<string> ans;
for(int i = 0; i< n; i++){
cin>>test;
flag = vali(test, s, alf);
if(flag) ans.push_back("YES");
else ans.push_back("NO");
}
for(int i = 0; i< n; i++)
cout<<ans[i]<<endl;
return 0;
}
Thanks!