首页 > 试题广场 >

福尔摩斯的约会 (20)

[编程题]福尔摩斯的约会 (20)
  • 热度指数:66273 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32M,其他语言64M
  • 算法知识视频讲解
大侦探福尔摩斯接到一张奇怪的字条:“我们约会吧! 3485djDkxh4hhGE 2984akDfkkkkggEdsb s&hgsfdk d&Hyscvnm”。大侦探很快就明白了,字条上奇怪的乱码实际上就是约会的时间“星期四 14:04”,因为前面两字符串中第1对相同的大写英文字母(大小写有区分)是第4个字母'D',代表星期四;第2对相同的字符是'E',那是第5个英文字母,代表一天里的第14个钟头(于是一天的0点到23点由数字0到9、以及大写字母A到N表示);后面两字符串第1对相同的英文字母's'出现在第4个位置(从0开始计数)上,代表第4分钟。现给定两对字符串,请帮助福尔摩斯解码得到约会的时间。
(注:两字符串的比较过程必须按照两字符串中对应的下标相同的字符进行比较!)

输入描述:
输入在4行中分别给出4个非空、不包含空格、且长度不超过60的字符串。


输出描述:
在一行中输出约会的时间,格式为“DAY HH:MM”,其中“DAY”是某星期的3字符缩写,即MON表示星期一,TUE表示星期二,WED表示星期三,THU表示星期
四,FRI表示星期五,SAT表示星期六,SUN表示星期日。题目输入保证每个测试存在唯一解。
示例1

输入

3485djDkxh4hhGE
2984akDfkkkkggEdsb
s&hgsfdk
d&Hyscvnm

输出

THU 14:04
import java.util.Scanner;
public class Main {
	private final static String[] DAY = {"MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN"}; 
	public static void main(String[] args) {
		StringBuilder sb = new StringBuilder();
		Scanner in = new Scanner(System.in);
		String l1 = in.nextLine();
		String l2 = in.nextLine();
		String l3 = in.nextLine();
		String l4 = in.nextLine();
		int len1 = Math.min(l1.length(), l2.length());
		int len2 = Math.min(l3.length(), l4.length());
		boolean flag1 = true;
		
		for(int i = 0;i<len1;i++){
			char c = l1.charAt(i);
			if(flag1&&c>='A'&&c<='G'){
				if(c==l2.charAt(i)){
					flag1 = !flag1;
					System.out.print(DAY[c-65]+" ");
				}
			}else if (!flag1&&c==l2.charAt(i)) {
				if(c>='0'&&c<='9'){
					System.out.print("0"+c+":");
					break;
				}else if (c>='A'&&c<='N') {
					System.out.print((c-55)+":");
					break;
				}
			}
		}
		
		for(int i = 0;i<len2;i++){
			char c = l3.charAt(i);
			if(c>='a'&&c<='z'&&c==l4.charAt(i)){
				if(i<10)
					System.out.print("0"+i);
				else
					System.out.print(i);
				break;
			}
		}
		in.close();
	}

}


编辑于 2016-06-06 22:26:20 回复(0)
import java.util.Scanner;
public class Main {

    public static void main(String[] args) {
        String DAY[]={"MON ","TUE ","WED ","THU ","FRI ","SAT ","SUN "};
        Scanner sc = new Scanner(System.in);
        String a = sc.next();
        String b = sc.next();
        String c = sc.next();
        String d = sc.next();
        char m[]=xiangtongday(a,b);

        //星期几
        System.out.print(DAY[m[0]-'A']);
       //小时
       if(m[1]<'9'&&m[1]>='0')
           System.out.print("0"+m[1]+":");
       else
           System.out.print((m[1]-'A')+10+":");

       //分钟
       if(count(c,d)<10&&count(c,d)>=0)
           System.out.print("0"+count(c,d));
       else
           System.out.print(count(c,d));

    }
    //返回 c[0]==星期几  c[1]=日期
    public static char[] xiangtongday(String a,String b){

         char x[];
         char y[];
         x=a.toCharArray();
         y=b.toCharArray();
         int length;
         int count1=0;
         int flag=0;
         char c[] = new char [20];
         if(a.length()<b.length())
             length=a.length();
         else
             length=b.length();
       for(int i=0;i<length;i++)
       {
           if(x[i]==y[i]&&x[i]>='A'&&x[i]<='G')
           {
              c[count1]=x[i];
              count1++;
              flag=i;
              break;
           }
       }
        for(int i=flag+1;i<=length;i++)
        {
            if(x[i]==y[i]&&((x[i]>='A'&&x[i]<='G')||x[i]>='0'&&x[i]<='9'))
            {
                c[count1]=x[i];
                break;
            }

        }

        return c;
        }

      //返回分钟
   public static int  count(String a,String b) {
       char x[] = new char[60];
       char y[] = new char[60];
       int count1=0;
       int length=0;
       x = a.toCharArray();
       y = b.toCharArray();
       if (a.length() < b.length())
           length = a.length();
       else
           length = b.length();
       for (int i = 0; i < length; i++) {
           if (x[i] == y[i] && x[i] >= 'a' && x[i] <= 'z') {
               count1 = i;
               break;
           }
       }
       return count1;
   }
}
是我不够细还是这个题目太细了啊,一个=号没加愣是看了半个小时才看出来😅

发表于 2021-05-14 19:20:52 回复(0)
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner input=new Scanner(System.in);
        String str1=input.nextLine();
        String str2=input.nextLine();
        String str3=input.nextLine();
        String str4=input.nextLine();
        input.close();
        int pos1=0,pos2=0;
        StringBuilder sb1=new StringBuilder();
        while(pos1<str1.length()&&pos2<str2.length()){
            if(str1.charAt(pos1)!=str2.charAt(pos2)){
                pos1++;
                pos2++;
            }else{
                sb1.append(str1.charAt(pos1));
                pos1++;
                pos2++;
            }
        }
        int pos3=0,pos4=0;
        while(pos3<str3.length()&&pos4<str4.length()){
            if(str3.charAt(pos3)!=str4.charAt(pos4)){
                pos3++;
                pos4++;
            }else{
                if(Character.isAlphabetic(str3.charAt(pos3)))
                    break;
                else{
                    pos3++;
                    pos4++;
                }
            }
        }
        int week=0;
        String Wee="";
        int hour=0;
        boolean flag=false;
        for(int i=0;i<sb1.length();i++){
            if(Character.isAlphabetic(sb1.charAt(i))&&flag==false){
                week=sb1.charAt(i)-'A'+1;
                flag=true;
            }else if(flag==true&&(Character.isDigit(sb1.charAt(i))||Character.isAlphabetic(sb1.charAt(i)))){
                if(Character.isAlphabetic(sb1.charAt(i)))
                    hour=9+sb1.charAt(i)-'A'+1;
                else
                    hour=sb1.charAt(i)-'0';
                break;
            }
        }
        switch(week){
            case 1:
                Wee="MON";
                break;
            case 2:
                Wee="TUE";
                break;
            case 3:
                Wee="WED";
                break;
            case 4:
                Wee="THU";
                break;
            case 5:
                Wee="FRI";
                break;
            case 6:
                Wee="SAT";
                break;
            case 7:
                Wee="SUN";
                break;
        }
        System.out.print(Wee+" "+(hour>9?hour:"0"+hour)+":"+(pos3>9?pos3:"0"+pos3));
    }

}

编辑于 2021-02-19 19:20:43 回复(0)
#include<iostream>
using namespace std;

int main()
{
	string date[7]={"MON","TUE","WED","THU","FRI","SAT","SUN"};
	string s1,s2,s3,s4;
	cin>>s1>>s2>>s3>>s4;


	int i,j,idx=0;
	
	for(i=0;i<s1.length()&&i<s2.length();i++){
		if(!idx){
			while(s1[i]!=s2[i] || s1[i]<65 || s1[i]>71){
				i++;
			}
			cout<<date[s1[i]-'A']<<" ";
			idx++;
		}else if(idx==1){
			while(s1[i]!=s2[i]){
				i++;
			}
			if(s1[i]>=48&&s1[i]<=57){
				cout<<0<<(s1[i]-'0')<<":";
				break;
			}else if(s1[i]>=65&&s1[i]<=78){
				cout<<(s1[i]-'A'+10)<<":";
				break;
			}
		}
	}
	
	for(i=0;i<s3.length()&&i<s4.length();i++){
		if(s3[i]==s4[i]&&s3[i]>=97&&s3[i]<=122){
			if(i<10) cout<<0<<i;
			else cout<<i;
			break;
		}
	}
	return 0;
}
题目没有说,相同的字符都出现在各个字符串同样的位置
发表于 2020-05-16 15:36:15 回复(0)
#include<bits/stdc++.h>

using namespace std;

int main() {
    string A,B,C,D;
    cin>>A>>B>>C>>D;
    char arrChar[2];
    int arrChar2;
    int k=0;
    int len1,len2;
    if(A.size()>B.size())
        len1=B.size();
    else
        len1=A.size();
    if(C.size()>D.size())
        len2=D.size();
    else
        len2=C.size();
    for(int i=0;i<len1;i++){
        if('A'<=A[i]&&A[i]<='Z'&&A[i]==B[i]&&k==0){
           arrChar[k++]=A[i];
        }else if(A[i]==B[i]&&k>0){
            arrChar[k++]=A[i];
            break;
        }
    }
    for(int i=0;i<len2;i++){
        if(C[i]==D[i]&&(('A'<=C[i]&&C[i]<='Z')||('a'<=C[i]&&C[i]<='z'))){
            arrChar2=i;
            break;
        }
    }
    //处理符号含义
    switch(arrChar[0]-'A'+1){
        case 1:
            cout<<"MON ";break;
        case 2:
            cout<<"TUE ";break;
        case 3:
            cout<<"WED ";break;
        case 4:
            cout<<"THU ";break;
        case 5:
            cout<<"FRI ";break;
        case 6:
            cout<<"SAT ";break;
        case 7:
            cout<<"SUN ";break;
        default:
            break;
    }
    if('0'<=arrChar[1]&&arrChar[1]<='9'){
        cout<<'0'<<arrChar[1]<<":";
    }else if('A'<=arrChar[1]&&arrChar[1]<='N'){
        cout<<arrChar[1]-'A'+10<<":";
    }
    if(0<=arrChar2&&arrChar2<=9)
        cout<<"0"<<arrChar2<<endl;
    else
        cout<<arrChar2<<endl;
}



发表于 2020-03-31 11:34:51 回复(0)
#include <stdio.h>
#include <ctype.h>

int main()
{
	int i;
	char strs[4][61];
	const char *days[] = {"MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN"};

	scanf("%s%s%s%s", strs[0], strs[1], strs[2], strs[3]);

	for(i = 0; strs[0][i] && strs[1][i]; ++i) {
		if(strs[0][i] == strs[1][i] && strs[0][i] >= 'A' && strs[0][i] <= 'G') {
			printf("%s ", days[strs[0][i] - 'A']);

			break;
		}
	}

	for(++i; strs[0][i]; ++i) {
		if(strs[0][i] == strs[1][i] && ((strs[0][i] >= 'A' && strs[0][i] <= 'N') || isdigit(strs[0][i]))) {
			if(isdigit(strs[0][i]))
				printf("0%c:", strs[0][i]);
			else
				printf("%d:", strs[0][i] - 'A' + 10);

			break;
		}
	}

	for(i = 0; strs[2][i] != strs[3][i] || !isalpha(strs[2][i]); ++i)
		;

	printf("%02d\n", i);

	return 0;
}

发表于 2020-01-14 20:38:42 回复(0)
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int maxn=65;
char src1[maxn],src2[maxn],src3[maxn],src4[maxn];
char sum[65];
int s=0;
void prin(int a,int b,char *a1,char *a2){
    int n;
    (a<b)?n=a:n=b;
    for(int i=0;i<n;i++){
        if(a1[i]==a2[i]) {
            s++;
            sum[s]=a1[i];
        }
    }
}
int main()
{
    int a1,a2,a3,a4;
    fgets(src1,64,stdin);
    fgets(src2,64,stdin);
    fgets(src3,64,stdin);
    fgets(src4,64,stdin);
    
    a1=strlen(src1)-1;
    a2=strlen(src2)-1;
    a3=strlen(src3)-1;
    a4=strlen(src4)-1;
    
    prin(a1,a2,src1,src2);
//    prin(a3,a4,src3,src4);
/*“DAY”是某星期的3字符缩写,即MON表示星期一,TUE表示星期二,WED表示星期三,THU表示星期
四,FRI表示星期五,SAT表示星期六,SUN表示星期日*/
    
        int j,k1=1;
        for(j=1;j<=s;j++)
        {
            if(sum[j]>'Z' || sum[j]<'A')
            k1++;
            else
            break;
        }
        switch(sum[k1]){
            case 'A':cout<<"MON";break;
            case 'B':cout<<"TUE";break;
            case 'C':cout<<"WED";break;
            case 'D':cout<<"THU";break;
            case 'E':cout<<"FRI";break;
            case 'F':cout<<"SAT";break;
            case 'G':cout<<"SUN";break;
        }
        cout<<" ";
        if(sum[k1+1]>='0' && sum[k1+1]<='9')        cout<<'0'<<sum[k1+1]<<":";
            else
                cout<<sum[k1+1]-'A'+10<<":";
                
                
        int k;
        (a3<a4)?k=a3:k=a4;
        for(int i=0;i<k;i++){
            if(src3[i]==src4[i] &&((src3[i]>='a' && src3[i]<='z') ||(src3[i]>='A' && src3[i]<='Z'))){
            
                if(i<10 && i>=0)
                    cout<<"0"<<i;
                    else
                    cout<<i;
                break;
            }
           
        }
        
    return 0;
}
发表于 2020-01-11 13:17:39 回复(0)
#include<iostream>
#include<string>
using namespace std;
int main(){
 string a,b,c,d;
 cin>>a>>b>>c>>d;
 char pday;
 int hour;
 bool first=true;
 for(int i=0 ; i < 60 ; i++){
   if(a[i]>='A'&&a[i]<='Z'&&a[i]==b[i]&&first==true){
    pday=a[i];
    first=false;
    continue;
   }
   if(a[i]==b[i]&&first==false){
    if(a[i]>='A'&&a[i]<='N'){
     hour=a[i]-'A'+10;
    }
    if(a[i]>='0'&&a[i]<='9'){
     hour=a[i]-'0';
    }
    break;
   }
 }
 int minute=0;
 for(int i = 0 ; i< 60 ; i++){
  if(c[i]>='a'&&c[i]<='z'&&d[i]>='a'&&d[i]<='z'&&c[i]==d[i]){
   minute = i;
   break;
  }
 }
 string days[7]={"MON","TUE","WED","THU","FRI","SAT","SUN"};
 string day;
 switch(pday){
  case 'A':
   day=days[0];
   break;
  case 'B':
   day=days[1];
   break;
  case 'C':
   day=days[2];
   break;
  case 'D':
   day=days[3];
   break;
  case 'E':
   day=days[4];
   break;
  case 'F':
   day=days[5];
   break;
  case 'G':
   day=days[6];
   break;
   }
   cout<<day<<(hour<10?" 0":" ")<<hour<<(minute<10?":0":":")<<minute;
   return 0;
}
发表于 2019-12-15 11:28:43 回复(0)

注意点

星期,小时和分钟都是有界限的,需要进行边界判断。星期是A-G大写字母,小时是:0-9、A-N大写字母,分钟是:0-60数字。对这些字母处理的同时需要做好边界检测。

/*
 * app=PAT-Basic lang=c++
 * https://pintia.cn/problem-sets/994805260223102976/problems/994805308755394560
 */
#include <cstdio>
#include <string>
#include <iostream>
using namespace std;

const string week[7] = {"MON","TUE","WED","THU","FRI","SAT","SUN"};
bool isUpperLetter(char c){
    return c >= 'A' && c <= 'Z';
}
bool isWeek(char c){
    return isUpperLetter(c) && (c < 'H');
}
bool isHour(char c){
    return isUpperLetter(c) && (c < 'O');
}
bool isNum(char c){
    return c >= '0' && c <= '9';
}
bool isSameLetter(char a,char b){
    if (a != b)
        return false;
    return (a >= 'a'&& a <= 'z') || (a >= 'A'&& a <= 'Z');
}
int main()
{
    string s1, s2, s3, s4;
    cin >> s1 >> s2 >> s3 >> s4;
    int minLen1 = s1.length() < s2.length() ? s1.length() : s2.length();
    int minLen2 = s3.length() < s4.length() ? s3.length() : s4.length();
    int i = 0;
    for (; i < minLen1; i++){
        if (s1[i] == s2[i] && isWeek(s1[i])){
            cout << week[s1[i]-'A'];
            break;
        }
    }
    for (i = i+1; i < minLen1;i++){
        if (s1[i] == s2[i]){
            if (isHour(s1[i])){
                printf(" %02d",10+s1[i]-'A');
                break;
            }
            else if (isNum(s1[i])){
                printf(" %02d", s1[i] - '0');
                break;
            }

        }
    }
    for (int j = 0; j < 61;j++){
        if (isSameLetter(s3[j], s4[j])&&j < 61){
            printf(":%02d\n",j);
            break;
        }
    }
    return 0;
}
发表于 2019-12-03 13:54:09 回复(0)
#include<stdio.h>
int list[3];
char hour;
char week[7][4]={"MON","TUE","WED","THU","FRI","SAT","SUN"};
int result1(char s1[60],char s2[60]){
    int result,count;
    for(int i=0;i<60;i++){
        if((s1[i]<=90&&s1[i]>=65)&&(s2[i]==s1[i])){
            result=int(s1[i])-64;
            list[0]=result;
            count=i+1;
            break;
        }
    }
    for(int n=count;n<60;n++){
        if(s1[n]==s2[n]){
        if(s1[n]>=48&&s1[n]<=57){
            result=int(s1[n])-48;
        }
        if(s1[n]>=65&&s1[n]<=78){
            result=int(s1[n])-55;
        }
        list[1]=result;
break;
        }
    }
    return 0;
}
int result2(char s1[60],char s2[60]){
    int result,count=1;
    for(int i=0;i<60;i++){
        if(((s1[i]<=90&&s1[i]>=65)||(s1[i]>=97&&s1[i]<=122))&&(s1[i]==s2[i])){
        list[2]=i;
        return 0;
        }
    }
    return 0;
}
int main(){
    char str[4][60];
    int i=0;
    while(scanf("%s",str[i])!=EOF){
        i++;
    }
    result1(str[0],str[1]);
    result2(str[2],str[3]);
    printf("%s %02d:%02d",week[list[0]-1],list[1],list[2]);
    return 0;
}

发表于 2019-11-28 11:57:18 回复(0)

/*
测试用例:
3485djEkxh4hhGE
2984akEfkkkkggEdsb
s&hgsfdk
d&Hyscvnm

对应输出应该为:
FRI 14:04
*/

/*
测试用例:
3485djGkxh4hhG2
2984akGfkkkkgg2dsb
s&hgsfdk
d&hyscvnm

对应输出应该为:
SUN 02:02
*/

/*
注意点:
两对字符串位置都是相同的,相同时才输出位置
第一对字符串 找第二次相等的字符是从第一次相等的下标开始
输出约会的时间,格式为 DAY HH:MM记得要补零
*/
#include<iostream>
#include<string>
using namespace std;
int main(){
string s1;
string s2;
string s3;
string s4;
cin>>s1>>s2>>s3>>s4;
int mark=0;
//WeekDay
for(int i=0;i<s1.size()&&i<s2.size();i++){//str.size()是用于求string类对象的成员函数,可以求字符串长度
if(s1[i]==s2[i]&&(s1[i]>='A'&&s1[i]<='G')){//s1[i]==s2[i]&&A----G,s1和s2相同位置第一次的值相等
switch(s1[i]){
case 'A': cout<<"MON ";break;
case 'B': cout<<"TUE ";break;
case 'C': cout<<"WED ";break;
case 'D': cout<<"THU ";break;
case 'E': cout<<"FRI ";break;
case 'F': cout<<"SAT ";break;
case 'G': cout<<"SUN ";break;
}
mark=i;//mark用来记录第一次的值相等的下标
break;
}
}
//Hour
for(int j=mark+1;j<s1.size()&&j<s2.size();j++){//mark+1第一次的值相等的下标之后开始,查找第二次相同位置上的值相等
if(s1[j]==s2[j]&&(s1[j]>='A' &&s1[j]<='N' || s1[j]>='0'&&s1[j]<='9')){
if(s1[j]>='A'&&s1[j]<='N'){//字母
int x=s1[j]-'A'+10;
cout<<x/10<<x%10<<":";
// 十位 个位
}
else{ //数字
int y=s1[j]-'0';//字符转整型
cout<<y/10<<y%10<<":";
// 十位 个位
}
break;
}
}
//Minute
for(int k=0;k<s3.size()&&k<s4.size();k++){
if(s3[k]==s4[k]&&(s3[k]>='A'&&s3[k]<='Z'||s3[k]>='a'&&s3[k]<='z')){
cout<<k/10<<k%10<<endl;
break;
}
}
// system("pause");
return 0;
}

发表于 2019-07-23 07:03:58 回复(0)
const readline = require("readline");

var Day = {
    A: "MON",
    B: "TUE",
    C: "WED",
    D: "THU",
    E: "FRI",
    F: "SAT",
    G: "SUN"
}
var Hours = {
    0: "00",
    1: "01",
    2: "02",
    3: "03",
    4: "04",
    5: "05",
    6: "06",
    7: "07",
    8: "08",
    9: "09",
    A: "10",
    B: "11",
    C: "12",
    D: "13",
    E: "14",
    F: "15",
    G: "16",
    H: "17",
    I: "18",
    J: "19",
    K: "20",
    L: "21",
    M: "22",
    N: "23"
};

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
let count = 0;
let first_str = "";
let first_arr = [];
let second_str = "";
let second_arr = [];
let min_length = 0;
let Day_NUM;
let temp_arr = [];
let third_str = "";
let third_arr = "";
let forth_str = "";
let forth_arr = "";
let result = "";
rl.on("line",(line)=>{
    
    if(count == 0){
        first_str = line;
        first_arr = first_str.split("");
        
    } else if (count == 1){
        second_str = line;
        second_arr = second_str.split("");
        if(first_arr.length <= second_arr.length){
            min_length = first_arr.length;
        } else if(first_arr.length > second_arr.length){
            min_length = second_arr.length;
        }
        for(let i=0; i<min_length; i++){
            if(first_arr[i] === second_arr[i]){
                temp_arr.push(first_arr[i]);
            }
        }
        for(let i=0; i<temp_arr.length; i++){
            if(/^[A-G]$/.test(temp_arr[i])){
                Day_NUM = i;
                break;
            }
        }
        temp_arr = temp_arr.slice(Day_NUM);
        result = result + Day[temp_arr[0]] + " " + Hours[temp_arr[1]] + ":";
        
    } else if (count == 2){
        third_str = line;
        third_arr = third_str.split("");
    } else{
        forth_str = line;
        forth_arr = forth_str.split("");
        if(third_arr.length <= forth_arr.length){
            min_length_34 = third_arr.length;
        } else if(third_arr.length > forth_arr.length){
            min_length_34 = forth_arr.length;
        }
        for(let i=0; i<min_length_34; i++){
            if(third_arr[i] === forth_arr[i] && /^[a-zA-Z]$/.test(third_arr[i])){
                time_num = i;
                break;
            }
        }
        time_num<10 ? result+="0"+time_num : result+=time_num;
        console.log(result);
        rl.close();
    }
    count<4 && count++;
})

这里用JS尝试写了下,看了下别人的代码,感觉像我这么蠢地把小时对应的表一个个列出来的可能只有我吧= - =
发表于 2019-03-17 14:52:00 回复(0)
#include <iostream>
#include <cstring>
using namespace std;
int main(){
   string a,b,c,d;
   cin>>a>>b>>c>>d;
   int hour,min,sec,flag=0;
   char tempmin;
   int i=0;
   for(i;a[i]!=NULL&&b[i]!=NULL;i++){ 
       if(flag==0&&a[i]==b[i]&&((a[i]>='A'&&a[i]<='Z')||(a[i]>='a'&&a[i]<='z'))){
         flag=1;
         if(a[i]<='z'&&a[i]>='a'){
            hour=a[i]-'a'+1;
            i++;
            
        }
            else if(a[i]<='Z'&&a[i]>='A')
           {
            hour=a[i]-'A'+1;
            i++;
           }
            
              
       }
       
    if(flag==1&&a[i]==b[i]){           
             tempmin = a[i];
             break;
      } 
   }  
   for(i=0;c[i]!=NULL&&d[i]!=NULL;i++){
   if(c[i]==d[i]&&((c[i]>'A'&&c[i]<'Z')||(c[i]>'a'&&c[i]<'z'))){ 
    sec=i; 
    break;
   }
  }
  //cout<<hour<<tempmin;
  switch (hour){
      case 1: cout<<"MON ";break;
      case 2: cout<<"TUE ";break;
      case 3: cout<<"WED ";break;
    case 4: cout<<"THU ";break;
    case 5: cout<<"FRI ";break;
    case 6: cout<<"SAT ";break;
    case 7: cout<<"SUN ";break;
  }
  if(tempmin>='0'&&tempmin<='9')
  {
  min=tempmin-'0';
  printf("%02d:",min);
  }
  
  else{
  min=tempmin-'A'+10;
  cout<<min<<":";
  }
  printf("%02d",sec);
  cout<<endl;
   return 0;
    
} 

发表于 2019-02-01 14:29:48 回复(0)
注意要对应位置的字符相同才算成对(调到崩溃)
注意序列长度不同
注意三个元素的判定依据
/**
 * 
 * @author ChopinXBP
 * 大侦探福尔摩斯接到一张奇怪的字条:“我们约会吧! 3485djDkxh4hhGE 2984akDfkkkkggEdsb s&hgsfdk d&Hyscvnm”。
 * 大侦探很快就明白了,字条上奇怪的乱码实际上就是约会的时间“星期四 14:04”
 * 前面两字符串中第1对相同的大写英文字母(大小写有区分)是第4个字母'D',代表星期四;第2对相同的字符是'E',
 * 那是第5个英文字母,代表一天里的第14个钟头(于是一天的0点到23点由数字0到9、 以及大写字母A到N表示);
 * 后面两字符串第1对相同的英文字母's'出现在第4个位置(从0开始计数)上,代表第4分钟。现给定两对字符串
 * 
 * 注意点:1.要对应位置的字符相同才算成对,2.注意序列长度不同,3.注意三个元素的判定依据
 * 
 */

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Scanner;

public class HolmesCode {     public static Scanner in = new Scanner(new BufferedInputStream(System.in));     public static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));     public static ArrayList<String> str = new ArrayList<>();     public static String[] week = { "MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN" };     public static int date = -1;     public static int hour = -1;     public static int min;     public static void main(String[] args) {         // TODO Auto-generated method stub         Read();         Decode();         Print();         out.close();         in.close();     }     public static void Read() {         for (int i = 0; i < 4; i++) {             String string = in.nextLine();             str.add(string);         }     }     public static void Decode() {         // 存放前两个序列的相同元素(注意序列长度不同)         ArrayList<Character> sameword = new ArrayList<>();         for (int i = 0; i < Math.min(str.get(0).length(), str.get(1).length()); i++) {             char word = str.get(0).charAt(i);             char word2 = str.get(1).charAt(i);             if (word == word2 && ((word >= 'A' && word <= 'Z') || (word >= '0' && word <= '9'))) {                 sameword.add(word);             }         }         // 解码日期和小时         for (int i = 0; i < sameword.size(); i++) {             Character word = sameword.get(i);             if (date == -1) {                 if (word >= 'A' && word <= 'Z') {                     date = word - 'A';                 }             } else {                 if (word >= 'A' && word <= 'N') {                     hour = word - 'A' + 10;                     break;                 } else if (word >= '0' && word <= '9') {                     hour = Integer.parseInt(word.toString());                     break;                 }             }             if (hour != -1)                 break;         }         // 解码分钟         for (int i = 0; i < Math.min(str.get(2).length(), str.get(3).length()); i++) {             char word = str.get(2).charAt(i);             char word2 = str.get(3).charAt(i);             if (word == word2 && ((word >= 'A' && word <= 'Z') || (word >= 'a' && word <= 'z'))) {                 min = i;                 break;             }         }     }     public static void Print() {         out.print(week[date] + ' ');         if (hour < 10) {             out.print('0');         }         out.print(hour);         out.print(':');         if (min < 10) {             out.print('0');         }         out.print(min);     }
}

发表于 2018-08-16 17:33:52 回复(0)
#include<stdio.h>
#include<math.h>
#include<string.h>
#define MAX 10000
char *getDay(char str);
int getHour(char str);

int main()
{
    char str[4][60];
    int i, len, count = 0;
    for(i = 0; i < 4; i++)
    {
        scanf("%s", str[i]);
    }
    len = strlen(str[0]) < strlen(str[1]) ? strlen(str[0]) : strlen(str[1]);
    for(i = 0; i < len; i++)
    {
        if((str[0][i] == str[1][i]) && str[0][i] >= 'A' && str[0][i] <= 'N')
        {
            if(!count)
            {
                printf("%s ", getDay(str[0][i]));
                count++;
            }
            else if(count == 1)
            {
                printf("%d:", getHour(str[0][i]));
                break;
            }
        }
        if((str[0][i] == str[1][i]) && count == 1 && str[0][i] >= '0' && str[0][i] <= '9')
        {
            printf("0%c:", str[0][i]);
            break;
        }
    }
    len = strlen(str[2]) < strlen(str[3]) ? strlen(str[2]) : strlen(str[3]);
    for(i = 0; i < len; i++)
    {
        if((str[2][i] == str[3][i]) && str[2][i] >= 'A' && str[2][i] <= 'z')
        {
            if(i < 10)
            {
                printf("0%d", i);
                break;
            }
            else
            {
                printf("%d", i);
                break;
            }
        }
    }
}

char *getDay(char str)
{
    switch(str)
    {
        case 'A': return "MON";
        case 'B': return "TUE";
        case 'C': return "WED";
        case 'D': return "THU";
        case 'E': return "FRI";
        case 'F': return "SAT";
        case 'G': return "SUN";
        default: return "NULL";
    }
}

int getHour(char str)
{
    switch(str)
    {
        case 'A': return 10;
        case 'B': return 11;
        case 'C': return 12;
        case 'D': return 13;
        case 'E': return 14;
        case 'F': return 15;
        case 'G': return 16;
        case 'H': return 17;
        case 'I': return 18;
        case 'J': return 19;
        case 'K': return 20;
        case 'L': return 21;
        case 'M': return 22;
        case 'N': return 23;
        default: return -1;
    }
}
发表于 2018-04-03 11:26:37 回复(0)
 可以AC,这个题目最重要的就是理解题意,第一个是判断大写字母,第二个是只判断字符,可以是大写字母,当然也可以是任意的字符,只是想说这个题目出得真随便,应该是英语翻译过来的 import java.util.Scanner;

public class Main {     @SuppressWarnings("resource")     public static void main(String[] args) {         Scanner in = new Scanner(System.in);         String[] stringArray = new String[4];         for (int i = 0; i < stringArray.length; i++) {             stringArray[i] = in.next();             // 这里真是坑苦我了,next()代表的是你接下来所有输入内容的第一项,nextline()代表如果你输入了一行,             // 那就是这一行,没有第几项的说法         }         // 现在已经拿到了四个字符串,开始进行处理         char weekday = '0';         // 建立一个字符类型的数组,存储第一个相同的字符与第二个相同的字符         char[] charArray = new char[2];         int charArrayIndex = 0;// 给字符类型的数组建立计数器         char finalFirstChar = 0;         char finalSecondChar = 0;         // 这里要明确的是第二个相同的字符         // 这里的相等是上下同位置相等         // 每一次循环过来这个i总会变了的,所以得到的值一直在变         int i;         for (i = 0; i < stringArray[0].length(); i++) {             if (stringArray[0].charAt(i) >= 'A' && stringArray[0].charAt(i) <= 'Z') {                 for (int j = 0; j < stringArray[1].length(); j++) {                     if (stringArray[0].charAt(i) == stringArray[1].charAt(j) && i == j) {                         charArray[0] = (char) stringArray[0].charAt(i);                         finalFirstChar = charArray[0];                         break;                     }                 }             }             if (charArray[0] != '\0') {                 break;             }         }         for (int i1 = i+1; i1 < stringArray[0].length(); i1++) {                 for (int j = 0; j < stringArray[1].length(); j++) {                     if (stringArray[0].charAt(i1) == stringArray[1].charAt(j) && i1 == j) {                             charArray[1] = (char) stringArray[0].charAt(i1);                             finalSecondChar = charArray[1];                             break;                 }             }             if (charArray[1] != '\0') {                 break;             }         }         // 做到这一步,已经拿到了星期几的,可以对这个字母做一个减去A的操作,得到的结果加一就是星期几         int weekdayNum = finalFirstChar - 'A';         String DAY = null;// 这就是星期几的前三个字母         switch (weekdayNum + 1) {         case 1:             DAY = "MON";             break;         case 2:             DAY = "TUE";             break;         case 3:             DAY = "WED";             break;         case 4:             DAY = "THU";             break;         case 5:             DAY = "FRI";             break;         case 6:             DAY = "SAT";             break;         case 7:             DAY = "SUN";             break;         default:             break;         }         // System.out.println(DAY);         // 星期几已经可以顺利输出,接下来研究第二个相同的字符         char secondCharacter = finalSecondChar;// 这是第二个相同的字符         String hour = null;         if (secondCharacter >= '0' && secondCharacter <= '9') {             hour = "0" + secondCharacter;         } else if (secondCharacter >= 'A' && secondCharacter <= 'N') {             hour = String.valueOf(secondCharacter - 'A' + 10);         }         // System.out.println(hour);         // 届此小时也已经打印出来了         int minute = 0;         String minuteString = null;         for (int i1 = 0; i1 < stringArray[2].length(); i1++) {             if ((stringArray[2].charAt(i1) >= 'A' && stringArray[0].charAt(i1) <= 'Z')                     || (stringArray[2].charAt(i1) >= 'a' && stringArray[0].charAt(i1) <= 'z')) {                 for (int j = 0; j < stringArray[3].length(); j++) {                     if (stringArray[2].charAt(i1) - stringArray[3].charAt(j) == 0&&i1==j) {                         minute = i1;                         break;                     }                 }             }             if (minute != 0) {                 break;             }         }         if (minute < 10) {             minuteString = "0" + String.valueOf(minute);         } else {             minuteString = String.valueOf(minute);         }         System.out.println(DAY + " " + hour + ":" + minuteString);     }

}

发表于 2017-09-18 20:31:03 回复(0)
用java的实现的方法,有什么可改进的吗?
public class Question4 {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		char[] chars1 = sc.next().toCharArray();
		char[] chars2 = sc.next().toCharArray();
		char[] chars3 = sc.next().toCharArray();
		char[] chars4 = sc.next().toCharArray();
		sc.close();
		String[] days = { "MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN" };
		String day="MON";
		String hour="00";
		// 对前两个字符数组进行比较
		int len1 = chars1.length;
		int len2 = chars2.length;
		int min = len1 < len2 ? len1 : len2;
		int count = 0; // 遇到相同字符的次数
		for (int i = 0; i < min; i++) {
			if (chars1[i] == chars2[i]) {
				if (count == 0 && !Character.isDigit(chars1[i]) && chars1[i] < 97) {
					int d = Character.toUpperCase(chars1[i]) - 65;
					day = days[d];
					count++;
				} else if (count == 1) {
					int h;
					if (!Character.isDigit(chars1[i])) {
						h = Character.toUpperCase(chars1[i]) - 64 + 9;
					} else {
						h = chars1[i] - 48;
					}
					hour = h+"";
					break;
				}
			}
		}
		String minute="00";
		// 对后两个字符串进行比较
		int len3 = chars3.length;
		int len4 = chars4.length;
		int min2 = len3 < len4? len3 : len4;
		for (int i = 0; i < min2; i++) {
			if(chars3[i]==chars4[i] && Character.isAlphabetic(chars3[i])){
				minute=i+"";
				break;
			}
		}
		hour=hour.length()==1?0+hour:hour;
		minute=minute.length()==1?0+minute:minute;
		System.out.printf("%s %s:%s",day,hour,minute);
	}
}

编辑于 2017-08-18 16:38:40 回复(0)
#include<iostream>
#include<stdio.h>
#include<math.h>
#include <string.h> 
using namespace std;
int main(){
char str[4][61],d[2];
int lg[4],k=0,m;
for(int i=1;i<=4;i++){
   scanf("%s",str[i]);}
for(int i=1;i<=4;i++){
   lg[i]=strlen(str[i]);}
if(lg[1]>lg[2]) lg[1]=lg[2];
if(lg[3]>lg[4]) lg[3]=lg[4];
for(int i=0;i<=lg[1];i++){
   if(k==1&&str[1][i]==str[2][i]){
      k++;d[k]=str[1][i];break;
      }
   if(k==0&&isupper(str[1][i])&&str[1][i]==str[2][i]){
      k++;d[k]=str[1][i];
      }
}
for(int i=0;i<=lg[3];i++){
   if(str[3][i]>='a' && str[3][i]<='z' && str[3][i]==str[4][i]){
      m=i;break;
      }
   if(str[3][i]>='A' && str[3][i]<='Z' && str[3][i]==str[4][i]){
      m=i;break;
      }
}
        switch(d[1])
            {
            case 'A':printf("MON ");break;
            case 'B':printf("TUE ");break;
            case 'C':printf("WED ");break;
            case 'D':printf("THU ");break;
            case 'E':printf("FRI ");break;
            case 'F':printf("SAT ");break;
            case 'G':printf("SUN ");break;
            default:printf("错误!");
            }
        if(d[2]>='A'&&d[2]<='N')
        printf("%d:",10+(d[2]-'A'));
        else printf("0%c:",d[2]);
printf("%02d\n",m);
 system("pause");
}
发表于 2017-08-16 18:28:41 回复(0)
#include<iostream>
#include<string>
using namespace std;
bool isSmall(char c)
{
    if((c>='a'&&c<='z')||(c>='A'&&c<='Z'))
        return true;
    return false;
}
bool isBig(char c)
{
    if(c>='A'&&c<='G')
        return true;
    return false;
}
bool isLegal(char c)
{
    if((c>='0'&&c<='9')||(c>='A'&&c<='N'))
        return true;
    return false;
}
int main()
{
    string s1,s2,s3,s4;
    //cin>>s1>>s2>>s3>>s4;
	s1="3485djDkxh4hhGE";
	s2="2984akDfkkkkggEdsb";
	s3="s&hgsfdk";
	s4="d&Hyscvnm";
    int index1=min(s1.size(),s2.size());
    int index2=min(s3.size(),s4.size());
    char c1,c2;
    int c3;
    bool frist=true;
    for(int i=0;i<index1;i++)
    {
        if(frist)
        {
        	if(s1[i]==s2[i]&&isBig(s1[i]))
        	{
                c1=s1[i];
                frist=false;
        	}
       	}
        else
        {
            if(s1[i]==s2[i]&&isLegal(s1[i]))
            {
                c2=s1[i];
                break;
            }
        }
    }
    for(int i=0;i<index2;i++)
    {
        if(s3[i]==s4[i]&&isSmall(s3[i]))
        {
           c3=i;
           break;
        }
    }
    switch(c1-'A'+1)
    {
        case 1:cout<<"MON"<<" ";break;
        case 2:cout<<"TUE"<<" ";break;
        case 3:cout<<"WED"<<" ";break;
        case 4:cout<<"THU"<<" ";break;
        case 5:cout<<"FRI"<<" ";break;
        case 6:cout<<"SAT"<<" ";break;
        case 7:cout<<"SUN"<<" ";break;
        default:break;
    }
    if(c2>='0'&&c2<='9')
        cout<<0<<c2-'0'<<":";
    else
        cout<<9+int(c2-'A'+1)<<":";
    if(c3<9)
        cout<<0<<c3<<endl;
    else
        cout<<c3<<endl;
    return 0;
}

发表于 2017-08-14 21:25:55 回复(0)
#!/usr/bin/env python
#-*- coding:utf8 -*-
def findTime():
    days = {'A':'MON',
            'B':'TUE',
            'C':'WED',
            'D':'THU',
            'E':'FRI',
            'F':'SAT',
            'G':'SUN'}
    time = []
    #这个循环用来找到第一个相同的大写字母,找到之后退出循环
    for i in s1:
        if i in s2 and i in days:
            time.append(i)
            break
    DAY, start, end = days[time[0]], s1.index(time[0]), s2.index(time[0])
    #start,end 分别用来记录第一个相同的大写字母在s1 和 s2的下标位置
    #因为题目说HH的范围在0~9和A~N之间,
    #找第二个相同字符就在第一个相同字母之后找符合条件的
    for i in s1[start+1:]:
        if i in s2[end+1:]:
            if 'A' <= i <= 'N' or i in "0123456789":
                time.append(i)
                break
    HH = time[1]

    if HH in "0123456789":
        HH = int(HH)
    else:
        HH = ord(HH) - ord('A') + 10

    #找s3和s4第一个相同的字符,字符条件为A~Z和a~z 找到之后退出循环   
    for i in range(len(s3)):
        if s3[i] == s4[i]:
            if 'A'<= s3[i] <= 'Z' or 'a' <= s3[i] <= 'z':
                time.append(i)
                break
    MM = time[2]
    return DAY, HH, MM


if __name__ == '__main__':
    s1 = raw_input()
    s2 = raw_input()
    s3 = raw_input()
    s4 = raw_input()
    DAY, HH, MM = findTime()
    print("%s %02d:%02d" % (DAY, HH, MM))

编辑于 2017-08-06 15:36:47 回复(0)