1061 Dating(字符串处理)--未完全通过测试用例

这类题目几乎不需要数据结构,算法基础,主要通过简单的逻辑流程和判断实现。

题目描述如下:
在这里插入图片描述
题目大致意思:
输入四个字符串,在头两个字符串中获得星期和小时的信息,在最后两个字符串中获得分钟的信息,星期的获取方法为,检查头两个字符串,第一次出现的相同位置的大写字母作为星期的编号(具体代表含义如题干所示);获得小时的方法为:检查头两个字符串,第二次出现的相同位置的数字或大写字母代表小时(具体代表含义如题干所示);获取分钟的方法为:检查最后两个字符串,得到第一次相同字母的出现位置,即代表分钟数。
提交结果:
只得到了14分,考虑了挺久,想不出遗漏了何种情况,暂时放下。
在这里插入图片描述

代码如下:

#include<iostream>
#include<string>
using namespace std;
int main()
{
    string str1, str2, str3, str4;
    string ans;
    string week[] = { "MON","TUE","WED","THU","FRI","SAT","SUN" };
    cin >> str1 >> str2 >> str3 >> str4;
    int count = 0;
    for (int i = 0; i < str1.size() && i < str2.size(); i++)
    {
        if (str1[i] == str2[i] && count == 0 && str1[i] >= 'A' && str1[i] <= 'G')
        {
            int day = str1[i] - 'A';
            ans =ans+ week[day]+" ";
            count++;
            continue;
        }
        if (str1[i] == str2[i] && count == 1 && ((str1[i] >= '0' && str1[i] <= '9') || (str1[i] >= 'A' && str1[i] <= 'N')))
        {
            int temp = 0;
            string t;
            if (str1[i] >= '0' && str1[i] <= '9')
            {
                temp = str1[i] - '0';
                t = '0' + to_string(temp);
            }
            else
            {
                temp = str1[i] - 'A' + 10;
                t = to_string(temp);
            }
            ans = ans + t + ':';
            break;
        }
    }
    for (int i = 0; i < str2.size() && i < str3.size(); i++)
    {
        if (str3[i] == str4[i]&&((str3[i]>='a'&&str3[i]<='z')|| (str3[i] >= 'A' && str3[i] <= 'Z')))
        {
            string temp;
            if (i < 10)
            {
                temp = '0' + to_string(i);
            }
            else {
                temp = to_string(i);
            }

            ans = ans + temp;
            break;
        }
    }
    cout << ans << endl;
}

提交后,排名上升到28245。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值