注意:跨年没有满分,没有去测试,题目不清楚去哪里测试,所以不清楚是否AC,如有错误请指出
古代先民认为,天下万物皆由五类元素组成,分别是金、木、水、火、土,彼此之间存在相生相克的关系。
相生关系为:木生火,火生土,土生金,金生水,水生木。
相克关系为:金克木,木克土,土克水,水克火,火克金。
本题就请你编写程序,判断任意一对给定的元素之间的关系。
输入格式:
输入在一行中给出一个正整数 N(≤10),随后 N 行,每行给出 2 个正整数 A
和 B
,为两种元素的编号。这里假设金、木、水、火、土的编号顺次为 1、2、3、4、5。
输出格式:
对输入的每一对 A
和 B
,如果 A
生 B
,则输出 A sheng B
;如果 A
克 B
,则输出 A ke B
。反之亦然。
输入样例:
2
4 2
5 3
输出样例:
2 sheng 4
5 ke 3
思路1:判断a等于1到5时,b等于多少
思路2:a+b之和的值为多少,再去判断
1 sheng 3
2 sheng 4
3 sheng 2
4 sheng 5
5 sheng 1
1 ke 2
2 ke 5
3 ke 4
4 ke 1
5 ke 3
#include<bits/stdc++.h>
using namespace std;
void check1(int a,int b){
int n=2;
while(n--){
if(a==1){
if(b==3){
cout << "1 sheng 3" << endl;
return ;
}
else if(b==2){
cout << "1 ke 2" << endl;
return ;
}
}
else if(a==2){
if(b==4){
cout << "2 sheng 4" << endl;
return ;
}
else if(b==5){
cout << "2 ke 5" << endl;
return ;
}
}
else if(a==3){
if(b==2){
cout << "3 sheng 2" << endl;
return ;
}
else if(b==4){
cout << "3 ke 4" << endl;
return ;
}
}
else if(a==4){
if(b==5){
cout << "4 sheng 5" << endl;
return ;
}
else if(b==1){
cout << "4 ke 1" << endl;
return ;
}
}
else if(a==5){
if(b==1){
cout << "5 sheng 1" << endl;
return ;
}
else if(b==3){
cout << "5 ke 3" << endl;
return ;
}
}
a^=b^=a^=b;//没找到结果,交换值继续判断
}
}
void check2(int a,int b){
int sum=a+b;
if(sum==3){
cout << "1 ke 2" << endl;
}
else if(sum==4){
if(a==1 || a==3){
cout << "1 sheng 3" << endl;
}
}
else if(sum==5){
if(a==3 || a==2){
cout << "3 sheng 2" << endl;
}
else if(a==4 || a==1){
cout << "4 ke 1" << endl;
}
}
else if(sum==6){
if(a==2 || a==4){
cout << "2 sheng 4" << endl;
}
else if(a==5 || a==1){
cout << "5 sheng 1" << endl;
}
}
else if(sum==7){
if(a==2 || a==5){
cout << "2 ke 5" << endl;
}
else if(a==3 || a==4){
cout << "3 ke 4" << endl;
}
}
else if(sum==8 && (a==5 || a==3)){
cout << "5 ke 3" << endl;
}
else if(sum==9 && (a==4 || a==5)){
cout << "4 sheng 5" << endl;
}
}
int main(){
int n,a,b;
cin >> n;
while(n--){
cin >> a >> b;
cout << a << " " << b << " ";
check2(a,b);
cout << endl;
}
return 0;
}