• [HDOJ3528]The Simple Programming Language


    水题~

    View Code
    #include <cstdio>
    #include
    <cstring>

    using namespace std;

    const int MAXW = 1024;
    const int MAXL = 1024000;

    int nw;
    bool ok;
    char input[MAXL];
    char word[MAXW][MAXL];

    void work(int start,int end)
    {
    if (start > end) return;

    if (start == end && word[start][0] == 'w')
    {
    int f = strchr(word[start],'(') - word[start];
    int e = strchr(word[start],')') - word[start];
    for (int i = f + 2;i < e - 1;i++)
    {
    ok
    = true;
    printf(
    "%c",word[start][i]);
    }
    return;
    }

    int cntif = 0;
    int idx = -1;

    for (int i = start + 1;i <= end;i++)
    if (word[i][0] == 'i') cntif++;
    else if (word[i][0] == 'e')
    {
    if (cntif == 0)
    {
    idx
    = i;
    break;
    }
    cntif
    --;
    }

    if (word[start][3] == '1')
    {
    if (idx == -1) work(start + 1,end);
    else work(start + 1,idx - 1);
    }
    else
    if (idx != -1)
    work(idx
    + 1,end);
    }

    int main()
    {
    int idx;
    while (gets(input))
    {
    nw
    = 0;
    for(idx = 0;input[idx] && input[idx] == ' ';idx++) ;
    for (int i = idx;input[i];i++)
    if (i == 0 || (input[i-1] == ' ' && input[i] != ' '))
    sscanf(input
    + i,"%s",word[nw++]);
    while (gets(input) && strlen(input) != 0)
    {
    for(idx = 0;input[idx] && input[idx] == ' ';idx++) ;
    for (int i = idx;input[i];i++)
    if (i == 0 || (input[i-1] == ' ' && input[i] != ' '))
    sscanf(input
    + i,"%s",word[nw++]);
    }

    ok
    = false;
    work(
    0,nw - 1);
    if(ok) printf("\n");
    }
    return 0;
    }
  • 相关阅读:
    thinkphp目录解析
    开发规范
    form
    命名空间
    类与对象
    OS知识点汇总
    C++每日一记!
    语言哲学和语言逻辑
    形式语言与自动机
    C#脚本
  • 原文地址:https://www.cnblogs.com/debugcool/p/HDOJ3528.html
Copyright © 2020-2023  润新知