当前位置:网站首页>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
边栏推荐
- How can we make money by making video clips from our media?
- Explain
- ESP at installation esp8266 and esp32 versions
- C simple question 2
- PCB wiring rules of PCI Express interface
- 【汇总】看过的一些Panel与视频
- New potential energy of industrial integration, Xiamen station of city chain technology digital summit successfully held
- 高效的S2B2C电商系统,是这样帮助电子材料企业提升应变能力的
- POJ2392 SpaceElevator [DP]
- C inheritance and interface design polymorphism
猜你喜欢
How to change the formula picture in the paper directly into the formula in word
SAP 内存参数调优过程
New potential energy of industrial integration, Xiamen station of city chain technology digital summit successfully held
Open source hardware small project: anxinco esp-c3f control ws2812
B_ QuRT_ User_ Guide(38)
B_ QuRT_ User_ Guide(36)
激光slam学习(2D/3D、偏实践)
SAP memory parameter tuning process
MySQL架构
PCB wiring rules of PCI Express interface
随机推荐
B_QuRT_User_Guide(37)
One of the anti climbing methods
ESP at installation esp8266 and esp32 versions
Balanced binary tree [AVL tree] - insert, delete
2022 Season 6 perfect children's model Shaanxi finals came to a successful conclusion
【路径规划】使用垂距限值法与贝塞尔优化A星路径
C语言学习
Map operation execution process
Anxinco esp32-a1s development board is adapted to Baidu dueros routine to realize online voice function
MongoDB快速入门
激光slam学习(2D/3D、偏实践)
Ora-01741 and ora-01704
Summary of SQL single table query 2020.7.27
[compilation principle] lexical analysis design and Implementation
【leetcode】day1
ASP. Net query implementation
Extract the file name under the folder under win
PCB wiring rules of PCI Express interface
JNI uses asan to check memory leaks
Anxin can internally test offline voice module vb-01 to communicate with esp-c3-12f