Acwing 1547. 约会

 

 题解:

#include <iostream>
using namespace std;
int main()
{
    string str1,str2,str3,str4;
    cin>>str1;
    cin>>str2;
    cin>>str3;
    cin>>str4;
    string DAY;
    char hour;
    int minute;
    int m=0;
    for(int i=0;i<int(str1.size());i++)
    {
        if(m==0&&str1[i]==str2[i]&&(str1[i]>='A'&&str1[i]<='G'))
        {
            DAY=str1[i];
            m++;
            continue;
        }
        if(m==1&&str1[i]==str2[i]&&(str1[i]>='0'&&str1[i]<='9'))
        {
            hour=str1[i];
            break;
        }
        if(m==1&&str1[i]==str2[i]&&(str1[i]>='A'&&str1[i]<='N'))
        {
            hour=str1[i];
            break;
        }

    }
    for(int i=0;i<int(str3.size());i++)
    {
        if(str3[i]==str4[i]&&((str3[i]>='A'&&str3[i]<='Z')||(str3[i]>='a'&&str3[i]<='z')))
        {
            minute=i;
            break;
        }
        
    }
    if(DAY=="A") cout<<"MON";
    if(DAY=="B") cout<<"TUE";
    if(DAY=="C") cout<<"WED";    
    if(DAY=="D") cout<<"THU";
    if(DAY=="E") cout<<"FRI";
    if(DAY=="F") cout<<"SAT";    
    if(DAY=="G") cout<<"SUN";
    cout<<' ';
    if(hour>='A'&&hour<='N')
    {
        cout<<hour-65+10;
    }
    else
    {
        cout<<'0'<<hour;
    }
    cout<<':';
    if(minute<10)
    {
        cout<<'0'<<minute;
    }
    else
    {
        cout<<minute;
    }

    
    
    
}

//切记别忘记了continue和break,可以把他看成一个基本的习惯。

对于这种字符串比较中,第一个相等的字符,第二个相等的字符题,需要我们去用另一个计数。

优秀题解:

#include <bits/stdc++.h>
using namespace std;
string weeks[7] = {"MON ","TUE ","WED ","THU ","FRI ","SAT ","SUN "};
int main(){
    string a,b,c,d;
    cin >> a >> b >> c >> d;
    char t[2];
    int pos,i = 0,j = 0;
    while(i < a.length() && i < b.length()){
        if(a[i] == b[i] && (a[i] >= 'A' && a[i] <= 'G')){
            t[0] = a[i];
            break;
        }
        i++;
    }
    i++;
    while(i < a.length() && i < b.length()){
        if(a[i] == b[i] && ((a[i] >= 'A' && a[i] <= 'N') || isdigit(a[i]))){
            t[1] = a[i];
            break;
        }
        i++;
    }
    while(j < c.length() && j < d.length()){
        if(c[j] == d[j] && isalpha(c[j])){
            pos = j;
            break;
        }
        j++;
    }
    cout << weeks[t[0] - 'A'];
    int m = isdigit(t[1]) ? t[1] - '0' : t[1] - 'A' + 10;
    printf("%02d:%02d",m,pos);
    return 0;
}

作者:MilkLu
链接:https://www.acwing.com/solution/content/84350/
来源:AcWing
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值