Codeforce system test — Strange behavior

Revision en4, by CazadorDivino, 2017-07-25 04:48:27

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!

Tags system test cases

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en4 English CazadorDivino 2017-07-25 04:48:27 7 Tiny change: 'answer to that of my comput' -> 'answer to my comput'
en3 English CazadorDivino 2017-07-25 04:47:22 262
en2 English CazadorDivino 2017-07-25 04:45:07 389
en1 English CazadorDivino 2017-07-25 04:41:18 2012 Initial revision (published)