Cod sursa(job #2269005)

Utilizator b10nd3Oana Mancu b10nd3 Data 25 octombrie 2018 16:56:02
Problema Algoritmul lui Dijkstra Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.46 kb
#include<stdio.h>
#include<stdlib.h>
#include<fstream>
#include<iostream>


using namespace std;

int semn1;
char unu;

void f(char doi){
	int semn2=1; char what;
	if(unu=='1'){
		if(doi=='1'){what='1'; }
		if(doi=='i'){what='i'; }
		if(doi=='j'){what='j'; }
		if(doi=='k'){what='k'; }
	}
	else if(unu=='i'){
		if(doi=='1'){what='i'; }
		if(doi=='i'){what='1'; semn2=-1; }
		if(doi=='j'){what='k'; }
		if(doi=='k'){what='j'; semn2=-1;}
	}
	else if(unu=='j'){
		if(doi=='1'){what='j'; }
		if(doi=='i'){what='k'; semn2=-1;}
		if(doi=='j'){what='1'; semn2=-1; }
		if(doi=='k'){what='i'; }
	}
	else if(unu=='k'){
		if(doi=='1'){what='k'; }
		if(doi=='i'){what='j'; }
		if(doi=='j'){what='i'; semn2=-1; }
		if(doi=='k'){what='1'; semn2=-1;}
	}
	if(semn1==semn2) semn1=1;
	else  semn1=-1;
	unu=what;	
}



int main(){
unsigned long long t, l,x;
string s, find="ijk";
ifstream in; ofstream out;
in.open("C-large.in"); out.open("test.out");
out.clear();
in>>t;
for(unsigned long long i=1;i<=t;i++){
	in>>l>>x>>s;
	unu=s[0];
	semn1=1;
	int where=0;
	for(unsigned long long j=1;j<l*x;j++){
		if(where==2 && unu=='k' && semn1==1 && j%l==0) j=l*x;
		while(unu==find[where] && where<=1 && semn1==1){
			unu=s[j%l]; semn1=1; j++;
			where++;
		}
		if(j<l*x) f(s[j%l]);
	
	}
   if(where==2 && unu=='k' && semn1==1) cout<<"Case #"<<i<<": YES"<<endl;
   else cout<<"Case #"<<i<<": NO"<<endl;
}





in.close(); out.close();	
return 0;	
}