当前位置:网站首页>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
边栏推荐
- Open source hardware small project: anxinco esp-c3f control ws2812
- Where are you going
- Enumeration, simulation, and sorting
- Reverse output three digit and arithmetic sequence
- [compilation principle] lexical analysis design and Implementation
- StringUtils工具类
- postgres timestamp转人眼时间字符串或者毫秒值
- May day C - most
- ASP. Net query implementation
- [untitled]
猜你喜欢
C cat and dog
[experiment sharing] log in to Cisco devices through the console port
Flash encryption process and implementation of esp32
B_QuRT_User_Guide(38)
B / Qurt Utilisateur Guide (36)
UE4_ Ue5 combined with Logitech handle (F710) use record
2022注册测绘师备考开始 还在不知所措?手把手教你怎么考?
Understand TCP's three handshakes and four waves with love
Svn relocation
Get started with mongodb
随机推荐
One week learning summary of STL Standard Template Library
USB (XVII) 2022-04-15
【7.4】25. K 个一组翻转链表
二叉排序树【BST】——创建、查找、删除、输出
B_QuRT_User_Guide(38)
First week of July
B_ QuRT_ User_ Guide(37)
Boost regex library source code compilation
Summary of common methods of object class (September 14, 2020)
Pycharm essential plug-in, change the background (self use, continuous update) | CSDN creation punch in
Anti climbing means cracking the second
The file format and extension of XLS do not match
List. How to achieve ascending and descending sort() 2020.8.6
webflux - webclient Connect reset by peer Error
How can we make money by making video clips from our media?
C语言学习
Display the server hard disk image to the browser through Servlet
Design and implementation of spark offline development framework
FPGA basics catalog
[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