1 条题解

  • 0
    @ 2026-10-31 13:30:41

    旅游

    先判断车厢相同,再比较座位号前两位。A/B/C在左侧,D/F在右侧。同侧且同排时,仅AB、BA、BC、CB、DF、FD为相邻。后面的每个条件都包含前面的条件。时间和额外空间均为O(1)。

    难度:1(geekpi-9-v2),依据:逐项判断车厢、排号、过道和相邻关系,直接条件表达式。

    #include <iostream>
    #include <vector>
    #include <string>
    #include <algorithm>
    using namespace std; int main(){string c,s,d,t;cin>>c>>s>>d>>t; bool a=c==d,b=a&&s.substr(0,2)==t.substr(0,2),e=b&&((s[2]<='C')==(t[2]<='C'));string pairs="AB BA BC CB DF FD";string p;p+=s[2];p+=t[2];bool f=e&&pairs.find(p)!=string::npos;cout<<a<<b<<e<<f<<"\n";}
    

    本数据为GeekPi自建训练数据,非官方评测数据。

    • 1

    信息

    ID
    2323
    时间
    1000ms
    内存
    256MiB
    难度
    入门
    标签
    递交数
    2
    已通过
    1
    上传者