PAT 乙级 1014
Posted moujun1001
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PAT 乙级 1014相关的知识,希望对你有一定的参考价值。
本题主要还是考验细致程度,需要把各种情况考虑到、题审清楚
1 #include <iostream> 2 #include <string> 3 using namespace std; 4 5 int main() { 6 string str[4]; 7 for (int i = 0; i < 4; i++) 8 getline(cin, str[i]); 9 int str_1 = 0, str_2 = 0; 10 str_1 = str[0].size(); 11 str_2 = str[1].size(); 12 int len = 0; 13 if (str_1 > str_2) 14 len = str_2; 15 else len = str_1; 16 int cnt = 0; 17 for (int i = 0; i < len; i++) { 18 if (str[0][i] == str[1][i]) { 19 char tmp = str[0][i]; 20 if (cnt == 0 && tmp >= ‘A‘ && tmp <= ‘G‘) { 21 cnt++; 22 switch(tmp) { 23 case ‘A‘: 24 cout << "MON "; 25 break; 26 case ‘B‘: 27 cout << "TUE "; 28 break; 29 case ‘C‘: 30 cout << "WED "; 31 break; 32 case ‘D‘: 33 cout << "THU "; 34 break; 35 case ‘E‘: 36 cout << "FRI "; 37 break; 38 case ‘F‘: 39 cout << "SAT "; 40 break; 41 case ‘G‘: 42 cout << "SUN "; 43 break; 44 } 45 } 46 else if (cnt == 1 && (isdigit(tmp) || tmp >= ‘A‘ && tmp <= ‘N‘)) { 47 cnt++; 48 switch(tmp) { 49 case ‘0‘: 50 cout << "00:"; 51 break; 52 case ‘1‘: 53 cout << "01:"; 54 break; 55 case ‘2‘: 56 cout << "02:"; 57 break; 58 case ‘3‘: 59 cout << "03:"; 60 break; 61 case ‘4‘: 62 cout << "04:"; 63 break; 64 case ‘5‘: 65 cout << "05:"; 66 break; 67 case ‘6‘: 68 cout << "06:"; 69 break; 70 case ‘7‘: 71 cout << "07:"; 72 break; 73 case ‘8‘: 74 cout << "08:"; 75 break; 76 case ‘9‘: 77 cout << "09:"; 78 break; 79 case ‘A‘: 80 cout << "10:"; 81 break; 82 case ‘B‘: 83 cout << "11:"; 84 break; 85 case ‘C‘: 86 cout << "12:"; 87 break; 88 case ‘D‘: 89 cout << "13:"; 90 break; 91 case ‘E‘: 92 cout << "14:"; 93 break; 94 case ‘F‘: 95 cout << "15:"; 96 break; 97 case ‘G‘: 98 cout << "16:"; 99 break; 100 case ‘H‘: 101 cout << "17:"; 102 break; 103 case ‘I‘: 104 cout << "18:"; 105 break; 106 case ‘J‘: 107 cout << "19:"; 108 break; 109 case ‘K‘: 110 cout << "20:"; 111 break; 112 case ‘L‘: 113 cout << "21:"; 114 break; 115 case ‘M‘: 116 cout << "22:"; 117 break; 118 case ‘N‘: 119 cout << "23:"; 120 break; 121 } 122 } 123 } 124 if (cnt > 1) 125 break; 126 } 127 str_1 = str[2].size(); 128 str_2 = str[3].size(); 129 if (str_1 > str_2) 130 len = str_2; 131 else len = str_1; 132 for (int i = 0; i < len; i++) { 133 if (str[2][i] == str[3][i] && ((str[2][i] >= ‘a‘ && str[2][i] <= ‘z‘) || (str[2][i] >= ‘A‘ && str[2][i] <= ‘Z‘))) { 134 if (i < 10) 135 cout << "0" << i << endl; 136 else 137 cout << i << endl; 138 break; 139 } 140 } 141 142 return 0; 143 }
以上是关于PAT 乙级 1014的主要内容,如果未能解决你的问题,请参考以下文章