Codeforce system test — Strange behavior

Правка en1, от CazadorDivino, 2017-07-25 04:41:18

Hi, can anyone help me figure out why the system gives a different answer to that of my computer for this code?.

Case: abc
a?a?a* 4 abacaba abaca apapa aaaaax

In Codeforce

Participant's output

NO NO NO YES

In my computer

NO YES NO YES

Answer for that case:

NO YES NO YES

#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
using namespace std;




#define SSTR( x ) static_cast< std::ostringstream & >( std::ostringstream() << std::dec << x ).str()
int ceil(int x, int k){
	if(x % k == 0) return x /k;
	return x/k+1;
}

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{
				//cout<< j<< " "<<test[j]<< " "<< (int)test[j]<<endl;
				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{
			//cout<< j<< " "<<test[j]<< " "<< (int)test[j]<<endl;
			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!

Теги system test cases

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en4 Английский CazadorDivino 2017-07-25 04:48:27 7 Tiny change: 'answer to that of my comput' -> 'answer to my comput'
en3 Английский CazadorDivino 2017-07-25 04:47:22 262
en2 Английский CazadorDivino 2017-07-25 04:45:07 389
en1 Английский CazadorDivino 2017-07-25 04:41:18 2012 Initial revision (published)