zoukankan      html  css  js  c++  java
  • 又是一道模拟题吧!

    题目如下:
    This cheeseburger you don't need
    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.
    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 <string.h>
    #include <cmath>
    #include <algorithm>
    #include <stdio.h>
    using namespace std;
    int main()
    {
        char a[1000],b[1000];
        while(gets(a))
        {
            //getchar();
            memset(b,' ',sizeof(b));
            int s1,s2,s3,s4,s5,s6,s7,s8,s9,s0,mark=0,k=0,i,j,m;
            int l=strlen(a);
            for(i=0; i<l; i++)
            {
                if(a[i]==',')
                {
                    s1=i;
                    mark=1;
                    for(j=0; j<s1; j++)
                    {
                        if(a[j]=='{') s2=j;
                        if(a[j]=='(') s3=j;
                        if(a[j]=='[') s4=j;
                    }
                    for(j=s1+2; j<l; j++)
                    {
                        if(a[j]=='{') s5=j;
                        if(a[j]=='(') s6=j;
                        if(a[j]=='[') s7=j;
                    }
    
                }
                else
                {
                    if(a[i]=='{') s8=i;
                    if(a[i]=='(') s9=i;
                    if(a[i]=='[') s0=i;
                }
            }
            if(mark==0)
            {
                for(i=s8+1; i<l; i++)
                {
                    if(a[i]=='}') break;
                    b[k++]=a[i];
                }
                b[k++]=' ';
                for(i=s9+1; i<l; i++)
                {
                    if(a[i]==')') break;
                    b[k++]=a[i];
                }
                b[k++]=' ';
                for(i=s0+1; i<l; i++)
                {
                    if(a[i]==']') break;
                    b[k++]=a[i];
                }
                if(b[0]<='z'&&b[0]>='a') b[0]=b[0]-32;
                for(i=1; i<l; i++)
                {
                    if(b[i]<='Z'&&b[i]>='A') b[i]=b[i]+32;
                }
                for(i=0; i<l; i++)
                {
                    cout<<b[i];
                }
                cout<<endl;
            }
            else
            {
                for(i=s2+1; i<s1; i++)
                {
                    if(a[i]=='}') break;
                    b[k++]=a[i];
                }
                b[k++]=' ';
                for(i=s3+1; i<s1; i++)
                {
                    if(a[i]==')') break;
                    b[k++]=a[i];
    
                }
                b[k++]=' ';
                for(i=s4+1; i<s1; i++)
                {
                    if(a[i]==']') break;
                    b[k++]=a[i];
    
                }
                b[k++]=',';
                b[k++]=' ';
                m=k;
                for(i=s1+2;i<l;i++)
                {
                    if(a[i]=='['||a[i]=='('||a[i]=='{') break;
                    b[k++]=a[i];
                }
                for(i=s5+1; i<l; i++)
                {
                    if(a[i]=='}') break;
                    b[k++]=a[i];
    
                }
                b[k++]=' ';
                for(i=s6+1; i<l; i++)
                {
                    if(a[i]==')') break;
                    b[k++]=a[i];
    
                }
                b[k++]=' ';
                for(i=s7+1; i<l; i++)
                {
                    if(a[i]==']') break;
                    b[k++]=a[i];
                }
                if(b[0]<='z'&&b[0]>='a') b[0]=b[0]-32;
                for(i=1; i<s1; i++)
                {
                    if(b[i]<='Z'&&b[i]>='A') b[i]=b[i]+32;
                }
                if(b[m]<='Z'&&b[m]>='A') b[m]=b[m]+32;
                for(i=0; i<l; i++)
                {
                    cout<<b[i];
                }
                cout<<endl;
            }
        }
        return 0;
    }
     
  • 相关阅读:
    CentOS 7 源码编译安装 Mysql 5.7
    Nginx 负载均衡 后端 监控检测 nginx_upstream_check_module 模块的使用
    cronolog 对 tomcat 7 进行日志切割
    OpenStack
    Oracle GoldenGate 异构平台同步(Mysql到Oracle)
    ELK 日志分析体系
    Tengine TCP 负载均衡
    MariaDB GTID 复制同步
    Mycat 安装配置
    Navicat破解
  • 原文地址:https://www.cnblogs.com/famousli/p/3874676.html
Copyright © 2011-2022 走看看