zoukankan      html  css  js  c++  java
  • 1061. Dating (20)

    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.

    Input Specification:

    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.

    Output Specification:

    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.

    Sample Input:

    3485djDkxh4hhGE 
    2984akDfkkkkggEdsb 
    s&hgsfdk 
    d&Hyscvnm
    

    Sample Output:

    THU 14:04

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    using namespace std;
    int main(){
    	char a[62],b[62],c[62],d[62];
    	char s[8][4]={"MON","TUE","WED","THU","FRI","SAT","SUN"};
    	scanf("%s%s%s%s",a,b,c,d);
    	int dd;
    	char h;
    	int hh;
    	int m;
    	int i,j;
    	int len=strlen(a);
    	int index1=-1,index2=-1;
    	for(i=0;i<len;i++){
    		if(a[i]==b[i]){
    			if(index1==-1&&(a[i]>='A'&&a[i]<='G')){
    				index1=i;
    			}else if(index1!=-1&&index2==-1&&((a[i]>='A'&&a[i]<='N'||a[i]>='0'&&a[i]<='9'))){
    				index2=i;
    				break;
    			}
    		}
    	}
    	if(a[index1]>='A'&&a[index1]<='G'){
    		dd=a[index1]-'A';
    	}
    	h=b[index2];
    	if(h>='0'&&h<='9'){
    		hh=h-'0';
    	}else if(h>='A'&&h<='N'){
    		hh=h-'A'+10;
    	}
    	len=strlen(c);
    	int index=0;
    	for(i=0;i<len;i++){
    		if(c[i]==d[i]&&(c[i]>='A'&&c[i]<='Z'||c[i]>='a'&&c[i]<='z')){
    			index=i;
    			break;
    		}
    	}
    	printf("%s %02d:%02d
    ",s[dd],hh,index);
    	return 0;
    } 
    

      

  • 相关阅读:
    【刷题-LeetCode】204. Count Primes
    【刷题-LeetCode】205. Isomorphic Strings
    【刷题-LeetCode】207. Course Schedule
    剑指offer题解——找出数组中重复的数字
    关于c++中vector操作
    动态规划算法
    分治算法
    从零学python——组合数据类型
    从零学python—PyInstaller库的介绍
    从零学python——代码复用与函数递归
  • 原文地址:https://www.cnblogs.com/grglym/p/7821274.html
Copyright © 2011-2022 走看看