C语言程序设计-1014 福尔摩斯的约会

妈了个鸡,老子这么优秀的代码第二个测试点死活过不去,终于发现错误了,Mon 小写了,我日

#include 
using namespace std;
int main(){
     
	string s1, s2, s3, s4, week[7] = {
     "MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN"};
	cin >> s1 >> s2 >> s3 >> s4;
	int flag = 1, n1, n2, n3;
	for(int i = 0; i < s1.length(); i++){
     
		if(s1[i] == s2[i]){
     
			if(flag && s1[i] >= 'A' && s1[i] <= 'G'){
     
				n1 = s1[i] - 'A' + 1; flag = 0;
			}else if(!flag && s1[i] >= '0' && s1[i] <= '9'){
     
				n2 = s1[i] - '0'; break;
			}else if(!flag && s1[i] >= 'A' && s1[i] <= 'N'){
     
				n2 = s1[i] - 'A' + 10; break;
			}
		}
	}
	for(int i = 0; i < s3.length(); i++){
     
		if(s3[i] == s4[i] && isalpha(s3[i])){
     
			n3 = i; break;
		}
	}
	printf("%s %02d:%02d", week[n1-1].c_str(), n2, n3); 
    return 0;
}

柳神代码,我还是找不出自己的错误

#include 
#include 
using namespace std;
int main() {
     
    string a, b, c, d;
    cin >> a >> b >> c >> d;
    char t[2];
    int pos, i = 0, j = 0;
    while(i < a.length() && i < b.length()) {
     
        if (a[i] == b[i] && (a[i] >= 'A' && a[i] <= 'G')) {
     
            t[0] = a[i];
            break;
        }
        i++;
    }
    i = i + 1;
    while (i < a.length() && i < b.length()) {
     
        if (a[i] == b[i] && ((a[i] >= 'A' && a[i] <= 'N') || isdigit(a[i]))) {
     
            t[1] = a[i];
            break;
        }
        i++;
    }
    while (j < c.length() && j < d.length()) {
     
        if (c[j] == d[j] && isalpha(c[j])) {
     
            pos = j;
            break;
        }
        j++;
    }
    string week[7] = {
     "MON ", "TUE ", "WED ", "THU ", "FRI ", "SAT ", "SUN "};
    int m = isdigit(t[1]) ? t[1] - '0' : t[1] - 'A' + 10;
    cout << week[t[0]-'A'];
    printf("%02d:%02d", m, pos);
    return 0;
}

你可能感兴趣的:(C语言程序设计)