当前位置:网站首页>507 field D - extraterrestrial relics
507 field D - extraterrestrial relics
2022-07-07 23:39:00 【Yuesi】
D - Extraterrestrial relics
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
边栏推荐
- postgres timestamp转人眼时间字符串或者毫秒值
- B_QuRT_User_Guide(40)
- MongoDB快速入门
- Anxinco EC series modules are connected to the multi protocol access products of onenet Internet of things open platform
- Where are you going
- Flash encryption process and implementation of esp32
- Anxin vb01 offline voice module access intelligent curtain guidance
- Right click the idea file to create new. There is no solution to create new servlet
- Idea automatically generates serialVersionUID
- Slam interview summary
猜你喜欢

SAP HR family member information

Right click the idea file to create new. There is no solution to create new servlet

B / Qurt Utilisateur Guide (36)

Benchmarking Detection Transfer Learning with Vision Transformers(2021-11)

Markdown

Markdown

B_ QuRT_ User_ Guide(37)

New potential energy of industrial integration, Xiamen station of city chain technology digital summit successfully held

Mobile heterogeneous computing technology - GPU OpenCL programming (basic)

Ora-01741 and ora-01704
随机推荐
How to login and enable synchronization function in Google browser
[summary] some panels and videos seen
【7.4】25. K 个一组翻转链表
Anxin can internally test offline voice module vb-01 to communicate with esp-c3-12f
Ora-01741 and ora-01704
USB (XIV) 2022-04-12
Dependency injection 2 advantage lifecycle
Anxin vb01 offline voice module access intelligent curtain guidance
C inheritance and interface design polymorphism
Explain
What if once again forgets the login password of raspberry pie? And you don't have a monitor yet! Today, I would like to introduce a method
C语言学习
[untitled]
Progress broadcast | all 29 shield machines of Guangzhou Metro Line 7 have been launched
StringUtils工具类
B_QuRT_User_Guide(36)
ESP at installation esp8266 and esp32 versions
Mobile heterogeneous computing technology - GPU OpenCL programming (basic)
[stm32+esp8266 connects to Tencent cloud IOT development platform 3] stm32+esp8266-01s dynamically registers devices on Tencent cloud (at instruction mode) -- with source code
[STM32 + esp-12s connect Tencent cloud IOT development platform 1] creation of cloud platform and burning of at firmware