点点滴滴”

导航

走上模拟道路 HDU4891

http://vjudge.net/contest/view.action?cid=51327#problem/D

 

Description

Yoda: May the Force be with you.
Master Yoda is the oldest member of the Jedi Council. He conducts preparatory classes of little Younglings up to the moment they get a mentor. All Younglings adore master Yoda and they hope to grow as strong and wise as he is. Just like all little children, Younglings are absolutely hooked on new games and ideas. Now they decided to learn to speak just like master Yoda. Help the Younglings understand how Yoda would say this or that sentence.
Yoda is speaking the Galactic language using the specific word order — so-called "object-subject-verb".
Your program receives a sentence that interests the Younglings. They have already highlighted all important parts in the sentence. They use the curly {}-brackets for objects, round ()-brackets for subjects and square []-brackets for verbs.
A sentence in the input can be simple or complex. If the sentence is complex, then it consists of two simple sentences separated by a comma. Sometimes a comma is followed by a conjunction that is not in the brackets.
Each simple question has exactly one object, one subject and one verb. Your task is to simply put them in the correct order. Namely, first the object, then the subject, finally the verb. Also, please do not forget that only the first word in the whole sentence should begin with capital letter.

Input

The single line contains a sentence that interests the Younglings. The length of the sentence does not exceed 100 characters. All the words in the sentence consist of Latin letters. The first letter of the first word is capitalized and the rest are small. The sentence may contain a comma. Each simple sentence contains all three types of brackets. Each pair of brackets surrounds one or more words. No pair of brackets can surround the other bracket. Brackets are always located on the borders of words. The words in the sentence are separated by a single space. There is no space character before a comma or a closing bracket and also after an opening bracket. The conjunction (which can be only after a comma) is the only word that is not surrounded by a pair of brackets.

Output

Print the sentence with the word order Yoda would use. All brackets must be omitted. You should separate the words by a single space.

Sample Input

input
(We) [are] {blind}, if (we) [could not see] {creation of this clone army}
output
Blind we are, if creation of this clone army we could not see
input
{Truly wonderful} (the mind of a child) [is]
output
Truly wonderful the mind of a child is

 

#include <iostream>
#include <cstring>
#include <cstdio>

using namespace std;

char str[105];
char ob[105],sub[105],veb[105];
int o,sb,ve;
int i,j;
int len,star;


int main()
{
    while(gets(str))
    {
        star=1;
        o=sb=ve=0;
        len=strlen(str);
        for(i=0;i<len;i++)
        {
            if(str[i]=='(')
            {
                i++;
                while(i<len&&str[i]!=')')
                {
                    sub[sb++]=str[i++];
                }
            }

            else if(str[i]=='{')
            {
                i++;
                while(i<len&&str[i]!='}')
                {
                    ob[o++]=str[i++];
                }
            }
            else if(str[i]=='[')
            {
                i++;
                while(i<len&&str[i]!=']')
                {
                    veb[ve++]=str[i++];
                }
            }
            else
            {
                if(str[i]==',')
                {
                    for(j=0;j<o;j++)
                    {
                        if(star)
                        {
                            if(ob[0]>='a'&&ob[0]<='z')
                            {
                                putchar(ob[0]-32);
                            }
                            else putchar(ob[0]);
                            star=0;
                            continue;
                        }
                        putchar(ob[j]);
                    }
                    putchar(' ');
                    o=0;
                    for(j=0;j<sb;j++)
                    {
                        if(j==0&&sub[0]<='Z'&&sub[0]>='A')
                            putchar(sub[j]+32);
                        else putchar(sub[j]);
                    }
                    putchar(' ');
                    sb=0;
                    for(j=0;j<ve;j++)
                    {
                        if(j==0&&veb[0]<='Z'&&veb[0]>='A')
                            putchar(veb[j]+32);
                        else putchar(veb[j]);
                    }
                    ve=0;
                    putchar(',');
                    i++;
                    while(str[i]!='{'&&str[i]!='('&&str[i]!='[')
                    {
                        if(i<len){
                            putchar(str[i]);
                            i++;
                        }
                        else
                        {
                            break;
                        }
                    }
                    i--;
                }
            }
        }
        if(o||sb||ve)
        {
            for(j=0;j<o;j++)
            {
                if(star)
                {
                    if(ob[0]>='a'&&ob[0]<='z')
                    {
                        putchar(ob[0]-32);
                    }
                    else putchar(ob[0]);
                    star=0;
                    continue;
                }
                putchar(ob[j]);
            }
            putchar(' ');
            for(j=0;j<sb;j++)
            {
                if(j==0&&sub[0]<='Z'&&sub[0]>='A')
                    putchar(sub[j]+32);
                else putchar(sub[j]);
            }
            putchar(' ');
            for(j=0;j<ve;j++)
            {
                if(j==0&&veb[0]<='Z'&&veb[0]>='A')
                    putchar(veb[j]+32);
                else putchar(veb[j]);
            }
        }
        putchar('\n');
    }
    return 0;
}

putchar();  字符输出  与cout没有其他差别

eg:putchar('a'-32)==A

     cout<<'a'-32<<endl;  ==65

 

 

The Great Pan

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1003    Accepted Submission(s): 352


Problem Description
As a programming contest addict, Waybl is always happy to take part in various competitive programming contests. One day, he was competing at a regional contest of Inventing Crappy Problems Contest(ICPC). He tried really hard to solve a "geometry" task without success.

After the contest, he found that the problem statement is ambiguous! He immediately complained to jury. But problem setter, the Great Pan, told him "There are only four possibilities, why don't you just try all of them and get Accepted?".

Waybl was really shocked. It is the first time he learned that enumerating problem statement is as useful as trying to solve some ternary search problem by enumerating a subset of possible angle!

Three years later, while chatting with Ceybl, Waybl was told that some problem "setters" (yeah, other than the Great Pan) could even change the whole problem 30 minutes before the contest end! He was again shocked.

Now, for a given problem statement, Waybl wants to know how many ways there are to understand it.

A problem statement contains only newlines and printable ASCII characters (32 ≤ their ASCII code ≤ 127) except '{', '}', '|' and '$'.

Waybl has already marked all ambiguity in the following two formats:

1.{A|B|C|D|...} indicates this part could be understand as A or B or C or D or ....
2.$blah blah$ indicates this part is printed in proportional fonts, it is impossible to determine how many space characters there are.

Note that A, B, C, D won't be duplicate, but could be empty. (indicate evil problem setters addedclarified it later.)

Also note that N consecutive spaces lead to N+1 different ways of understanding, not 2N ways.

It is impossible to escape from "$$" and "{}" markups even with newlines. There won't be nested markups, i.e. something like "${A|B}$" or "{$A$|B}" or "{{A|B}|C}" is prohibited. All markups will be properly matched.
 

 

Input
Input contains several test cases, please process till EOF.
For each test case, the first line contains an integer n, indicating the line count of this statement. Next n lines is the problem statement.
1 ≤ n ≤ 1000, size of the input file will not exceed 1024KB.
 

 

Output
For each test case print the number of ways to understand this statement, or "doge" if your answer is more than 105.
 

 

Sample Input
9 I'll shoot the magic arrow several times on the ground, and of course the arrow will leave some holes on the ground. When you connect three holes with three line segments, you may get a triangle. {|It is hole! Common sense!| No Response, Read Problem Statement|don't you know what a triangle is?} 1 Case $1: = >$ 5 $/*This is my code printed in proportional font, isn't it cool?*/ printf("Definitely it is cooooooool \ %d\n",4 * 4 * 4 * 4 * 4 * 4 * 4 * 4 * 4 * 4 * 4 * 4 * 4 * 4 * 4 * 4 * 4 * 4);$ 2 $Two space$ and {blue| red} color!
 

 

Sample Output
4 4 doge 6
 
 
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstring>

using namespace std;
#define LL long long

char str1[1000000];
char str[10000000];

int main()
{
    int n;
    while(scanf("%d",&n) != EOF)
    {
        memset(str,'/0',sizeof(str));
        LL ans = 1 ;
        LL tans=1;
        int len = 0;
        getchar();
        for(int i =1 ; i <= n; i ++)
        {
            gets(str1);
            int len1 = strlen(str1);
            for(int j = 0 ; j < len1 ; j++)
                str[j+len] = str1[j];
            len = len + len1;
        }

        int is = 0 ;
        int t  = 0 ;
        int ok = 0 ;

        for(int i = 0 ; i < len ; i ++)
        {
            if(ok == 1)
                break;
            if(is)
            {
                if(str[i] == ' ')
                {
                    t++;
                    if(str[i+1] != ' ')
                    {
                        tans *=(t+1);
                        t = 0 ;
                    }
                }
                else if(str[i] == '$')
                {
                    is = 0 ;
                    ans = tans * ans;
                    tans = 1;
                }
                if(tans > 100000)
                {
                    ok = 1;
                }
            }
            else
            {
                if(str[i] == '{')
                {
                    int t = 1 ;
                    int j ;
                    for(j = i +1; ; j ++)
                    {
                        if(str[j] == '}')
                            break;
                        if(str[j] == '|')
                            t ++ ;
                    }
                    i = j;
                    ans *= t ;
                    if(ans > 100000)
                    {
                        ok  = 1;
                    }
                }
                else
                {
                    if(str[i] == '$')
                        is = 1;
                }
            }
        }
        if(ok )
            printf("doge\n");
        else
            printf("%I64d\n",ans);
    }
    return 0;
}

 

posted on 2014-07-29 09:40  点点滴滴”  阅读(158)  评论(0编辑  收藏  举报