Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

有限状态机+递归

Posted by uuuouou at 2013-12-25 19:59:09 on Problem 1896
#include <cstdio>
#include <cctype>

void newline(int spaces)
{
    if(spaces > 0) putchar('\n');
    for(int i = 0; i < spaces; ++i) putchar(' ');
}
void inout(int level)
{
    newline(level << 2);
    
    int c;
    bool afterPeriod = false;
    while((c = getchar()) != -1){
        if(isspace(c)) continue;
        if(c == '{'){
            if(level) putchar(' ');
            putchar('{');
            inout(level+1);     //start a new level
        }
        else if(c == ';'){
            putchar(';');
            afterPeriod = true;
        }
        else if(c == '}'){
            if(level > 1) newline((level-1) << 2);
            else putchar('\n');
            putchar('}');       //last level's end
            return;             
        }
        else if(c == ','){
            putchar(',');
            putchar(' ');
        }
        else{
            if(afterPeriod){
                newline(level << 2);
                afterPeriod = false;
            }
            putchar(c);
        }
    }
}

int main()
{
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    
    inout(0);
    
    return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator