1 #include <iostream> 2 #include<string.h> 3 using namespace std; 4 char Lleft[3][100]; 5 char Lright[3][100]; 6 char result[3][100]; 7 bool wight(char c,bool b); 8 9 int main(){ 10 int n; 11 cin>>n; 12 for(int i=0;i<=n;i++) { 13 14 for (int j = 0; j < 3; ++j) { 15 cin>>Lleft[i]>>Lright[i]>>result[i]; 16 17 } 18 19 char c; 20 for (c = 'A'; c <= 'L'; c++) { 21 if (wight(c, 1)) { 22 cout << c << "is ," << "heavy"; 23 break;//第一次忘记加break了,感觉哪里不对劲但是就是忘记了 24 } 25 if (wight(c, 0)) { 26 27 cout << c << "is," << "light"; 28 break; 29 } 30 31 } 32 } 33 } 34 bool wight(char c,bool b){ 35 36 37 for (int i = 0; i < 3; ++i) { 38 39 //这步把轻的中的左边赋值给了一个指针,这样两个问题可以化成一个 40 //本来写的是弄成两个分开挨个想,唉其实还是错误率高啊 41 42 43 char *Left,*Right; 44 if(b){ 45 Left=Lleft[i]; 46 Right=Lright[i]; 47 } 48 else{ 49 Right=Lleft[i]; 50 Left=Lright[i]; 51 52 } 53 switch(result[i][0]){ 54 case'u': 55 if(strchr(Right,c)==NULL){ 56 return false; 57 } 58 break; 59 case 'e': 60 if(strchr(Right,c)||strchr(Left,c)){ 61 return false; 62 } 63 break; 64 case 'd': 65 if(strchr(Left,c)==NULL){ 66 return false; 67 } 68 break; 69 } 70 71 72 73 } 74 return true; 75 }