首页 > 试题广场 >

Dating (20)

[编程题]Dating (20)
  • 热度指数:2463 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32M,其他语言64M
  • 算法知识视频讲解
Sherlock Holmes received a note with some strange strings: "Let's date! 3485djDkxh4hhGE 2984akDfkkkkggEdsb
s&hgsfdk d&Hyscvnm". It took him only a minute to figure out that those strange strings are actually referring to the
coded time "Thursday 14:04" -- since the first common capital English letter (case sensitive) shared by the first two
strings is the 4th capital letter 'D', representing the 4th day in a week; the second common character is the 5th capital
letter 'E', representing the 14th hour (hence the hours from 0 to 23 in a day are represented by the numbers from 0 to
9 and the capital letters from A to N, respectively); and the English letter shared by the last two strings is 's' at the 4th
position, representing the 4th minute. Now given two pairs of strings, you are supposed to help Sherlock decode the
dating time.

输入描述:
Each input file contains one test case. Each case gives 4 non-empty strings of no more than 60 characters without white space in 4 lines.


输出描述:
For each test case, print the decoded time in one line, in the format "DAY HH:MM", where "DAY" is a 3-character abbreviation for the days 
in a week -- that is, "MON" for Monday, "TUE" for Tuesday, "WED" for Wednesday, "THU" for Thursday, "FRI" for Friday, "SAT" for
Saturday, and "SUN" for Sunday. It is guaranteed that the result is unique for each case.
示例1

输入

3485djDkxh4hhGE<br/>2984akDfkkkkggEdsb<br/>s&hgsfdk<br/>d&Hyscvnm

输出

THU 14:04
啥头像
是相同位置的相同字符,大大降低难度,挨个判断即可!

代码如下:
#include <iostream>
#include <stdio.h>
#include <string.h>

using namespace std;

char day[][4] = {"MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN"};

int main()
{
    char str1[61], str2[61], str3[61], str4[61];
    scanf("%s%s%s%s", str1, str2, str3, str4);
    int len1, len2, len3, len4;
    len1 = strlen(str1); len2 = strlen(str2);
    len3 = strlen(str3); len4 = strlen(str4);
    int idx1=0, d=0, h=0, m=0;
    // 寻找d
    for(; idx1<len1&&idx1<len2; idx1++) {
        if(str1[idx1]>='A' && str1[idx1]<='G') {
            if(str1[idx1] == str2[idx1]) {
                d = (str1[idx1]-'A')+1; break;
            }
        }
    }
    // 寻找h
    for(idx1++; idx1<len1&&idx1<len2; idx1++) {
        if((str1[idx1]>='0'&&str1[idx1]<='9')||(str1[idx1]>='A'&&str1[idx1]<='N')) {
            if(str1[idx1] == str2[idx1]) {
                if(str1[idx1]>='0'&&str1[idx1]<='9') {
                    h = (str1[idx1]-'0');
                } else {
                    h = (str1[idx1]-'A') + 10;
                }
                break;
            }
        }
    }
    // 寻找m
    for(int i=0; i<len3&&i<len4; i++) {
        if((str3[i]>='a'&&str3[i]<='z')||(str3[i]>='A'&&str3[i]<='Z')) {
            if(str3[i] == str4[i]) {
                m = i; break;
            }
        }
    }
    printf("%s %02d:%02d", day[d-1], h, m);
    return 0;
} 


发表于 2015-12-23 22:22:25 回复(0)

import java.util.*;
public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            Map<String,String> map = new HashMap<>();
            map.put("A","MON");
            map.put("B","TUE");
            map.put("C","WED");
            map.put("D","THU");
            map.put("E","FRI");
            map.put("F","SAT");
            map.put("G","SUN");
            String s1 = sc.nextLine();
            String s2 = sc.nextLine();
            StringBuilder sb = new StringBuilder();
            int i = 0;
            for (;i<s1.length() && i<s2.length();i++){
                if (s1.charAt(i) == s2.charAt(i) && Character.isUpperCase(s1.charAt(i))){
                    sb.append(map.get(s1.charAt(i)+"") + " ");
                    break;
                }
            }
            for (int j = i+1;j<s1.length() && j<s2.length();j++){
                if (s1.charAt(j) == s2.charAt(j)){
                    if (Character.isDigit(s1.charAt(j))){
                        sb.append("0"+(s1.charAt(j)-48)+":");
                    }else {
                        sb.append(s1.charAt(j)-55 + ":");
                    }
                    break;
                }
            }
            String s3 = sc.nextLine();
            String s4 = sc.nextLine();
            for (int k = 0;k<s3.length() && k<s4.length();k++){
                if (s3.charAt(k) == s4.charAt(k) && Character.isLetterOrDigit(s3.charAt(k))){
                    if (k>9)
                        sb.append(k+"");
                    else
                        sb.append("0"+k);
                    break;
                }
            }
            System.out.println(sb);
        }
    }
}
发表于 2018-11-27 17:00:54 回复(0)

/首先判断第一个字符串,如果第一个字符串有第一个相同的则进行相应的匹配***作
如果第二个字符相等则输出时刻
然后进行第二个字符串匹配并且在a和z之间
然后输出分钟即可
/

import java.io.*;
public class Main {

public static void main(String[] args) throws IOException
{
    BufferedReader reader=new BufferedReader(new InputStreamReader(System.in));
   String first=new String(reader.readLine());
   String secong =new String(reader.readLine());
   String third=new String(reader.readLine());
   String fird=new String(reader.readLine());
   String [] week={"MON","TUE","WED","THU","FRI","SAT","SUN"};
   int flag=0;
   for(int i=0;i<first.length()&&i<secong.length();i++)
   {
       if(first.charAt(i)==secong.charAt(i)&&flag==0&&first.charAt(i)>='A'&&first.charAt(i)<='G')
       {

           System.out.print(week[first.charAt(i)-'A']+' ');
           flag=1;
       }
       else if(first.charAt(i)==secong.charAt(i)&&flag==1)
       {
            if(first.charAt(i)>='0'&&first.charAt(i)<='9')
            {
                System.out.print("0");
                System.out.print(first.charAt(i)+":");
                break;
            }
            else if(first.charAt(i)>='A'&&first.charAt(i)<='N')
            {
                flag=first.charAt(i)-'A'+10;
                System.out.print(flag+":");
                break;
            }
       }
   }

   for(int i=0;i<third.length()&&i<fird.length();i++)
   {
       if(third.charAt(i)==fird.charAt(i)&&fird.charAt(i)>='a'&&fird.charAt(i)<='z')
       {
           if(i<10) {
               System.out.print('0');
               System.out.print(i);
               break;
           }
           else
           {
               System.out.print(i);
               break;
           }
       }
   }


}

}

发表于 2018-10-08 19:11:14 回复(0)
L=[input() for i in range(4)]
n,m,res=min(len(L[0]),len(L[1])),min(len(L[2]),len(L[3])),[]
week=['MON','TUE','WED','THU','FRI','SAT','SUN']
for i in range(n):
    x,y=L[0][i],L[1][i]
    if not res and x==y and x>='A' and x<='G':
        res.append(week[ord(x)-ord('A')])
    elif len(res)==1 and x==y and ((x>='0' and x<='9') or (x>='A' and x<='Z')):
        t=int(x) if x.isdigit() else ord(x)-ord('A')+10
        res.append(t)
for i in range(m):
    x,y=L[2][i],L[3][i]
    if x==y and x>='A' and x<='z':
        res.append(i)
        break
print('{} {:02d}:{:02d}'.format(res[0],res[1],res[2]))

发表于 2018-09-05 23:36:58 回复(0)
思路:按部就班。
#include <iostream>
#include <string>

using namespace std;


int main()
{
    string week[] = { "MON","TUE","WED","THU","FRI","SAT","SUN" };
    string n1, n2, n3, n4;
    string rlt;
    int count = 0;
    cin >> n1 >> n2 >> n3 >> n4;
    for (int i = 0; i < n1.size() && i < n2.size(); i++)
    {
        if (n1[i] == n2[i])
        {
            if(!count && (n1[i] >= 'A' && n1[i] <= 'Z'))
                count++;
            else if(count && ((n1[i] >= '0' && n1[i] <= '9') || (n1[i] >='A' && n1[i] <='N')))
            {
                count++;
            }
            if(count == 1)
                rlt += week[n1[i] - 'A'];
            else if(count == 2)
            {
                if (n1[i] >= '0' && n1[i] <= '9')
                {
                    rlt += " 0";
                    rlt += n1[i];
                }
                else
                {
                    rlt += " ";
                    if (n1[i] >= 'A' && n1[i] <= 'J')
                    {
                        rlt += "1";
                        rlt += n1[i] - 'A' + '0';
                    }
                    else
                    {
                        rlt += "2";
                        rlt += n1[i] - 'K' + '0';
                    }
                    
                }
                rlt += ":";
                break;
            }
        }
    }
    for (int i = 0; i < n3.size() && i < n4.size(); i++)
    {
        if (n3[i] == n4[i] && ((n3[i] >= 'a' && n3[i] <= 'z') ||( n3[i] >='A' && n3[i] <= 'Z')))
        {
            rlt += i / 10 + '0';
            rlt += i % 10 + '0';
            break;
        }
    }
    cout << rlt << endl;
    system("pause");
}

发表于 2018-08-25 23:08:20 回复(0)
s1, s2, s3, s4 = input(), input(), input(), input()
week = ['MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT', 'SUN']
t = [x[0] for x in zip(s1,s2) if x[0]==x[1]]
i = 0
while i<len(t):
    if t[i].isupper():
        break
    i += 1
d, h = t[i], t[i+1]
z = list(zip(s3,s4))
m = [i for i in range(len(z)) if z[i][0]==z[i][1] and z[i][0].isalpha()][0]
day = week[ord(d)-ord('A')]
hh = int(h) if '0'<=h<='9' else ord(h)-ord('A')+10
mm = int(m)
print('{} {:02d}:{:02d}'.format(day,hh,mm))

发表于 2018-05-02 19:46:20 回复(0)
#include <cstdio>
#include <cstring>
using namespace std;

int main(){
    char s1[70], s2[70], s3[70], s4[70];
    char week[7][5] = {"MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN"};
    gets(s1);
    gets(s2);
    gets(s3);
    gets(s4);
    int i;
    for(i = 0;i < strlen(s1) && i < strlen(s2);i++){
        if(s1[i] == s2[i] && s1[i] >= 'A' && s1[i] <= 'G'){
            printf("%s ", week[s1[i] - 'A']);
            break;
        }
    }

    for(i++;i < strlen(s1) && i < strlen(s2);i++){
        if(s1[i] == s2[i]){
            if(s1[i] >= '0' && s1[i] <= '9'){
                printf("%02d", s1[i] - '0');
                break;
            }else if(s1[i] >= 'A' && s1[i] <= 'N'){
                printf("%02d", s1[i] - 'A' + 10); 
                break;
            }
        }
    }

    for(int j = 0;j < strlen(s3) && j < strlen(s4);j++){
        if(s3[j] == s4[j]){
            if((s3[j] >= 'A' && s3[j] <= 'Z') || (s3[j] >= 'a' && s3[j] <= 'z')){
                printf(":%02d", j);
                break;
            }
        }
    }

    return 0;
}
发表于 2018-03-01 15:53:06 回复(0)
//没想到这么无脑...
#include <cstdio>
#include <string>
#include <iostream>
using namespace std;
string week[8] = {"00", "MON", "TUE", "WED", "THU",
                  "FRI", "SAT", "SUN"};
int main(){
    string str1, str2, str3, str4;
    cin >> str1 >> str2 >> str3 >> str4;
    int len1 = (str1.length() < str2.length()) ? str1.length() : str2.length();
    int len2 = (str3.length() < str4.length()) ? str3.length() : str4.length();
    int cnt = 1;
    for(int i=0; i<len1; i++){
        if(cnt == 1 && str1[i] == str2[i] && (str1[i] >= 'A' && str1[i] <= 'Z')){
            char c = str1[i];
            int pos = c - 'A' + 1;
            cout << week[pos] << " ";
            cnt ++;
            continue;
        }
        if(cnt == 2 && str1[i] == str2[i] && ((str1[i] >= '0' && str1[i] <= '9')|| (str1[i] >= 'A' && str1[i] <= 'N'))){
            char c = str1[i];
            if(c >= '0' && c <= '9'){
                printf("0%c:", c);
            }
            else if(c >= 'A' && c <= 'N'){
                int min = c - 'A' + 10;
                printf("%d:", min);
            }
            break;
        }
    }
    for(int i=0; i<len2; i++){
        if(str3[i] == str4[i] && ((str4[i] <= 'Z' && str4[i] >= 'A') || (str4[i] >='a' && str4[i] <='z'))){
            printf("%02d\n", i);
            break;
        }
    }
    return 0;
}

发表于 2017-09-08 01:13:40 回复(0)
无脑输出。。。。
#include<iostream>
#include<iomanip>
using namespace std;

int main(){
	string str1,str2,str3,str4;
	int count = 1;
	cin>>str1>>str2>>str3>>str4;
	int n = str1.length() > str2.length() ? str1.length() : str2.length();
	for(int i=0; i<n; i++){
		if(count == 1 && str1[i] == str2[i] && str1[i] >='A' && str1[i] <= 'G'){
			switch(str1[i]){
				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;
			}
			count++;
			continue;
		}
		if(count == 2 && str1[i] == str2[i] && (str1[i] >= '0' && str1[i] <='9' || str1[i] >= 'A' && str1[i] <= 'N')){
			if(str1[i] >= '0' && str1[i] <= '9'){
				printf("%02d:",(int)(str1[i] - '0'));
			}
			else{
				printf("%02d:",(int)(str1[i] - 'A' + 10));
			}
			break;
		}
	}
	n = str3.length() > str4.length() ? str3.length() : str4.length();
	count = 0;
	for(int i=0; i<n; i++){
		if(str3[i] == str4[i] && (str4[i] <= 'Z' && str4[i] >= 'A' || str4[i] >='a' && str4[i] <='z')){
			printf("%02d",i);
			break;
		}
	}
	return 0;
}

发表于 2017-02-28 10:44:04 回复(0)
#include<stdio.h>
#include<string.h>
int main()
{
char str[4][61],day[7][4]={"MON","TUE","WED","THU","FRI","SAT","SUN"};;
int i;
scanf("%s %s %s %s",str[0],str[1],str[2],str[3]);
for(i=0;i<strlen(str[0])&&i<strlen(str[1]);i++)
{
if(str[0][i]==str[1][i])
{
if(str[0][i]>='A'&&str[0][i]<='G')
{
printf("%s ",day[str[0][i]-'A']);
break;
}
}
}
for(int j=i+1;j<strlen(str[0])&&j<strlen(str[1]);j++)
{
if(str[0][j]==str[1][j])
{
char c=str[0][j];
if(c>='0'&&c<='9')
{
printf("%02d:",c-'0');
break;
}
else if(c>='A'&&c<='G')
{
printf("%02d:",c-'A'+10);
break;
}
}
}
for(i=0;i<strlen(str[2])&&i<strlen(str[3]);i++)
{
if(str[2][i]==str[3][i]&&(str[2][i]>='a'&&str[2][i]<='z')||(str[2][i]>='A'&&str[2][i]<='Z'))
{
printf("%02d",i);
break;
}
}
return 0;
}
发表于 2016-01-19 10:03:55 回复(0)
这个题目主要考察理解能力。
1.日期输出:字符串中相对位置相同,在A-G之间;
2.小时输出:字符串中相对位置相同,在0-9和A-N之间;
3.分钟输出:根据两个字符串中的相同位置的相等字符来判定分钟。
发表于 2015-07-02 21:11:13 回复(0)