zoukankan      html  css  js  c++  java
  • A1061 Dating [字符串比较]

    1061 Dating (20)(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
    

    题目大意:给出四个字符串,前两个字符串确定日期和小时, 后两个字符串确定分钟;

    1. 日期:前两个字符串第一个相等的大写字母(位置相同,字母相同)A~G 分别表示星期一到星期天
    2. 小时:在找到日期的字符串后面继续查找,找到第一个相同的数字或字母(09,AN)(位置也要相同),分别表示0~23
    3. 分钟:在后面两个字符串中查找,第一个相等的字母,不分大小写, 字母相等的位置就是分钟
    #include<iostream>
    #include<string>
    #include<cstring>
    using namespace std;
    string s[7] = { "MON","TUE","WED","THU","FRI","SAT","SUN" };
    int main()
    {
    	char s1[60],s2[60], s3[60], s4[60]; char c1, c2, c3;
    	int temp;
    	cin >> s1 >> s2 >> s3 >> s4;
    	int a = strlen(s1);
    	int b = strlen(s2); 
    	int c;
    	if (a <= b)
    		c = a;
    	else
    		c = b;
    	for (int i = 0; i < c; i++)
    	{
    		if (s1[i] == s2[i] && s1[i] <= 'G' && s1[i] >= 'A')
    		{
    			c1 = s1[i];
    			temp = i;
    			break;
    		}	
    	}
    	for (int i = temp + 1; i < c; i++)
    	{
    		if (s1[i] == s2[i] && ((s1[i] <= '9' && s1[i] >= '0') || (s1[i] >= 'A' && s1[i] <= 'N')))
    		{
    			c2 = s1[i];
    			break;
    		}
    	}
    	int a2 = strlen(s3);
    	int b2 = strlen(s4);
    	if (a2 <= b2)
    		c = a2;
    	else
    		c = b2;
    	for (int i = 0; i < c; i++)
    	{
    		if (s3[i] == s4[i] && (s3[i] <= 'z' && s3[i] >= 'a') || (s3[i] >= 'A' && s3[i] <= 'Z'))
    		{
    			c3 = s3[i];
    			temp = i;
    			break;
    		}
    	}
    
    	int n1 = c1 - 'A'; int n2;
    	if (c2 <= '9' && c2 >= '0')
    		n2 = c2 - '0';
    	else
    		n2 = c2 - 'A' + 10;
    	cout << s[n1] << " ";
    	cout << n2 / 10 << n2 % 10 << ":" << temp / 10 <<temp % 10;
    }
    
  • 相关阅读:
    【dp】P1982 小朋友的数字
    NOIp2017囤题计划
    Java语言编写计算器(简单的计算器)
    关于建立Android工程R文件丢失的问题
    读《黑客与画家》
    格式化输出%、基本运算符
    常量、变量;基本数据类型;input()、if、while、break、continue
    初遇Linux
    MVC5+EF6 入门完整教程10 数据查询更新
    Razor语法和Razor引擎大全
  • 原文地址:https://www.cnblogs.com/Hsiung123/p/13812091.html
Copyright © 2011-2022 走看看