当前位置:网站首页>507 field D - extraterrestrial relics

507 field D - extraterrestrial relics

2022-07-07 23:39:00 Yuesi

subject

Your friend Jones is a star adventurer , You know , Star adventurers always encounter some strange situations . Today Jones sent a message to you for help .

Jones found an ancient relic on a planet not far from the earth , There are strange mechanisms on the gate of ancient relics . Jones came to a conclusion through a period of exploration combined with his adventure experience : Two words appear on the screen of the mechanism every time , If the dictionary order of the first word is less than that of the second word , You need to press the green button ; Otherwise, press the red button .

There is an additional problem to pay attention to . Because the relics are old , There are some differences between the language used by the owner of the ruins and the dictionary order of our language . Of course , The well-informed Jones must know these differences , He will tell you the correct dictionary order . Then can you help him write a program to unlock the mechanism of the gate ?

PS: Words contain only lowercase letters

for example :uvwxyzabcdefghijklmnopqrst

Express , In relic language ,u It is the smallest in the dictionary , and t Is the most ordered in the dictionary . According to their dictionary order ,u be ranked at a In front of .

Input

first line , A length of 26 String of lowercase letters ( It's the dictionary preface Jones told you , The earlier the letters, the smaller the dictionary order , There will be no duplicate lowercase letters ) The second line , A number n, It means that it needs to be done later n Compare it to (1 <= n <= 100000) After that n That's ok , Two words per line , Space separates the middle

Output

If you enter two words , According to the dictionary order of relics , The dictionary order of the first word is less than that of the second word , Output “green”, Otherwise output “red”.

The sample input

uvwxyzabcdefghijklmnopqrst
5
apple banana
banana blueberry
apple watermelon
vegetable banana
apple ap

Sample output

green
green
red
green
red

#include<bits/stdc++.h>
using namespace std;
int main(){
    
	string ans;
	cin>>ans;
	// Give the dictionary order 
	long long int n;
	// The number of word groups to compare 
	string a,b;
	long long int la,lb;
	scanf("%lld",&n);
	int k1,k2;
	bool t=0;
	// Judge whether there is output 
	while(n--){
    
		t=0;
		cin>>a>>b;
		la=a.size();
		lb=b.size();
		int m=min(la,lb);
		if(a==b){
    
		// Judge whether the words are equal 
			t=1;
			printf("red\n");
		}else{
    
			for(long long int i=0;i<m;i++){
    
				if(ans.find(a[i])<ans.find(b[i])){
    
					printf("green\n");
					t=1;
					break;
				}
				if(ans.find(a[i])>ans.find(b[i])){
    
					printf("red\n");
					t=1;
					break;
				}
			}
			if(t==0){
    
			// No output means that you can find another word in one word 
				if(la>lb){
    
				// Compare their lengths 
					t=1;
					printf("red\n");
				}else{
    
					t=1;
					printf("green\n");
				}
			}
		} 
	}	
	return 0;
}

Pay attention to the range of data, such as n, la, lb

原网站

版权声明
本文为[Yuesi]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202130556375270.html