• 2019 gplt团体程序设计天梯赛总结


    分很菜…

    以后写题一定记得把题意理清楚了再开始写。

    模拟题还是大坑,代码还是写得不够多,代码量一大就写bug。

    补题

    l1-8 估值一亿的AI核心代码

    补题链接:https://pintia.cn/problem-sets/994805046380707840/problems/1111914599412858885

    #include <iostream>
    #include <cstdio>
    #include <cstdlib>
    #include <cmath>
    #include <cstring>
    #include <algorithm>
    #include <string>
    #include <vector>
    #include <queue>
    #include <set>
    #include <map>
    #define INF 0x3f3f3f3f
    #define ll long long
    #define lowbit(x) (x&(-x))
    #define PI acos(-1)
    #define ms(x,y) memset(x, y, sizeof(x))
    using namespace std;
    
    const int maxn = 1e4+7;
    char s[maxn];
    char punc[] = "`~!@#$%^&*()_+-={}|[]\;':",./<>?";
    char canYou[] = "can you";     // 7
    char couldYou[] = "could you"; // 9
    char me[] = "me";              // 2
    
    inline bool isPunc(char c) { for(int i=0;punc[i]!='';i++) if(c == punc[i]) return true; return false; }
    inline bool isCapit(char c) { return c >= 'A' && c <= 'Z'; }
    inline bool isSepar(char c) { return (c == ' ') | isPunc(c); }
    inline bool isCanYou(int ptr, int lim)
    {
        for(int i=0;canYou[i] != ''; i++)
        {
            if(i+ptr >= lim) return false;
            if(s[i+ptr] != canYou[i]) return false;
        }
        return 7+ptr >= lim || isSepar(s[7+ptr]);
    }
    inline bool isCouldYou(int ptr, int lim)
    {
        for(int i=0;couldYou[i] != ''; i++)
        {
            if(i+ptr >= lim) return false;
            if(s[i+ptr] != couldYou[i]) return false;
        }
        return 9+ptr >= lim || isSepar(s[9+ptr]);
    }
    inline bool isMe(int ptr, int lim)
    {
        for(int i=0;me[i] != ''; i++)
        {
            if(i+ptr >= lim) return false;
            if(s[i+ptr] != me[i]) return false;
        }
        return 2+ptr >= lim || isSepar(s[2+ptr]);
    }
    
    int print(int i, int lim)
    {
        if(isCanYou(i+1, lim))
        {
            printf("I can");
            i += 7;
        }
        else if(isCouldYou(i+1, lim))
        {
            printf("I could");
            i += 9;
        }
        else if(isMe(i+1, lim))
        {
            printf("you");
            i += 2;
        }
        else if(i+1 < lim && s[i+1] == 'I' && (i+2 >= lim || isSepar(s[i+2])))
        {
            printf("you");
            i += 1;
        }
        return i;
    }
    
    int main()
    {
        int T;
        scanf("%d", &T);
        getchar();
        while(T--)
        {
            cin.getline(s, maxn); puts(s);
            int len =  strlen(s);
            
            int tp_begin = -1, tp_end = 0;
            int now_cnt = 0;
            for(int i=0; i<len; i++)
                if(s[i] != ' ')
                {
                    tp_begin = i-1; break;
                }
            for(int i=len-1; i>=0; i--)
                if(s[i] != ' ')
                {
                    tp_end = i; break;
                }
            
            for(int i=tp_begin+1; i<=tp_end; i++)
            {
                if(s[i] == ' ')
                {
                    int j = i+1;
                    while(j <= tp_end && s[j] == ' ') j ++; // i+1~j-1: redundant space
                    if(!isPunc(s[j]))
                        s[now_cnt++] = s[i];
                    i = j-1;
                }
                else
                {
                    if(isCapit(s[i]) && s[i] != 'I') s[i] = s[i] - 'A' + 'a';
                    else if(s[i] == '?') s[i] = '!';
                    s[now_cnt ++] = s[i];
                }
            } s[now_cnt] = '';
            
            printf("AI: ");
            int i = 0;
            while(i < now_cnt && s[i] == ' ') i ++; // first un-space
            i = print(i-1, now_cnt);
            for(i=i+1;i<now_cnt;i++)
            {
                if(isSepar(s[i]))
                {
                    printf("%c", s[i]);
                    i = print(i, now_cnt);
                    
                }
                else printf("%c", s[i]);
            } puts("");
        }
    }
  • 相关阅读:
    CCNA 6.9
    CCNA 6.5
    Google search
    CCNA 4.14 TP Correction
    CCNA 6.3
    CCNA 6.6
    有关 英语学习的一些网站
    法语学习笔记
    垃圾邮件分类(Scala 版本)
    SQL 面试经典问题 行列互相转化
  • 原文地址:https://www.cnblogs.com/HazelNut/p/10634245.html
Copyright © 2020-2023  润新知