18 D - This cheeseburger you don't need(URAL1993)

题意硬伤,看样例看懂得!实际就是个模拟题,没想到没加括号的不能在中间出现,哔了狗了!

#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string.h>
#include<string>
#include<stdlib.h>
using namespace std;


char s[110];
char ans[3][110];
char chu[110];
char dou[3];
int main()
{
    int i;
    gets(s);
    int l=strlen(s);
    memset(chu,0,sizeof(chu));
    int k=0,xl=0;
    for(i=0;i<l;i++)
    {
        if(s[i]=='{')
        {
            int j=0;
            i++;
            while(i!=l&&s[i]!='}')
            {
                ans[0][j++]=s[i];
                i++;
            }
            ans[0][j++]=' ';
            ans[0][j]='\0';
        }
        else if(s[i]=='(')
        {
            int j=0;
            i++;
            while(i!=l&&s[i]!=')')
            {
                ans[1][j++]=s[i];
                i++;
            }
            ans[1][j++]=' ';
            ans[1][j]='\0';
        }
        else if(s[i]=='[')
        {
            int j=0;
            i++;
            while(i!=l&&s[i]!=']')
            {
                ans[2][j++]=s[i];
                i++;
            }
            ans[2][j]='\0';
        }
        else if(s[i]==',')
        {
                dou[0]=',';
                dou[1]=' ';

                strcat(chu,ans[0]);
                strcat(chu,ans[1]);
                strcat(chu,ans[2]);
                strcat(chu,dou);
                i++;
                xl=strlen(chu);
                int k=xl;
                while(i!=l&&s[i]!='['&&s[i]!='('&&s[i]!='{')
                {

                    chu[k++]=s[i];
                    i++;
                }
                i--;
                memset(ans,0,sizeof(ans));
        }

    }
    strcat(chu,ans[0]);
    strcat(chu,ans[1]);
    strcat(chu,ans[2]);

    xl=strlen(chu);
    for(i=0;i<xl;i++)
    {
        if(i==0)
        {
            if(chu[i]<='z'&&chu[i]>='a')
                chu[i]=chu[i]-32;
        }
        else
        {
            if(chu[i]<='Z'&&chu[i]>='A')
                chu[i]=chu[i]+32;
        }
    }
    printf("%s\n",chu);
    return 0;
}

 

posted @ 2016-05-19 19:02  吾心安处  阅读(125)  评论(0编辑  收藏  举报