1 条题解

  • 0
    @ 2026-9-30 12:57:32

    C++ :

    
    #include <cstdio>
    #include <cstring>
    /* 每行两个非空白分隔的串,判断第一个是否为第二个的子序列;
       输出 Case i: yes/no(题面保证只有 3 行,这里按读到 EOF 通用处理)。 */
    static char line[400005];
    int main(){
        int no = 0;
        while(fgets(line, sizeof(line), stdin)){
            char *p = line;
            while(*p == ' ' || *p == '\t') p++;
            if(*p == '\n' || *p == '\r' || *p == 0) continue;
            char *s = p;
            while(*p && *p != ' ' && *p != '\t' && *p != '\n' && *p != '\r') p++;
            if(!*p) continue;
            *p++ = 0;
            while(*p == ' ' || *p == '\t') p++;
            char *t = p;
            while(*p && *p != '\n' && *p != '\r') p++;
            *p = 0;
            no++;
            int j = 0;
            for(int i = 0; s[i]; i++){
                while(t[j] && t[j] != s[i]) j++;
                if(!t[j]){ j = -1; break; }
                j++;
            }
            printf("Case %d: %s\n", no, j < 0 ? "no" : "yes");
        }
        return 0;
    }
    
    
    • 1

    信息

    ID
    2817
    时间
    1000ms
    内存
    256MiB
    难度
    (无)
    标签
    递交数
    0
    已通过
    0
    上传者