URAL 1993 This cheeseburger you don't need 模拟题
This cheeseburger you don't need
题目连接:
http://acm.timus.ru/problem.aspx?space=1&num=1993
Description
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
(We) [are] {blind}, if (we) [could not see] {creation of this clone army}
Sample Output
Blind we are, if creation of this clone army we could not see
Hint
题意
没括号的原样输出,有括号的就优先输出大括号,中括号,然后小括号这样
句首需要大写
题解:
模拟题,烦……
代码
#include <bits/stdc++.h>
using namespace std;
string base;
vector < string > str;
string Clear_32(string s){
string res;
int Ed = s.size() - 1;
for( ; Ed >= 0 && s[Ed] == ' ' ; -- Ed);
for(int i = 0 ; i < s.size() ; ++ i){
if( s[i] != ' '){
for(int j = i ; j <= Ed ; ++ j) res.push_back( s[j] );
break;
}
}
return res;
}
void Solve( string s , int INDEX ){
stack < int > sp;
string F[4];
int pos[4];
F[0]=F[1]=F[2]=F[3]="";
bool find = false;
for(int i = 0 ; i < s.size() ; ++ i){
if(s[i] == '[' || s[i] == '(' || s[i] == '{'){
sp.push( i );
if( find == false ) F[0]=s.substr(0,i);
find = true;
if(s[i] == '{') pos[1] = i;
else if(s[i] =='(') pos[2] = i;
else pos[3] = i;
}
else if(s[i] == ']' || s[i] == ')' || s[i] == '}'){
string * ptr = F;
int extra = 0;
if( s[i] == '}' ) extra = 1;
else if( s[i] == ')' ) extra=2;
else extra=3;
ptr += extra;
*ptr=s.substr(pos[extra]+1,i-pos[extra]-1);
}
}
for(int i = 1 ; i < 4 ; ++ i) F[i] = Clear_32( F[i] );
cout << F[0];
if(INDEX==0){
for(int i = 0 ; i < 4 ; ++ i)
if(F[i].size()){
if(F[i][0] <= 'z' && F[i][0] >='a'){
F[i][0] = F[i][0] - 'a' + 'A';
}
for(int j = 1 ; j < F[i].size() ; ++ j){
if(F[i][j] <= 'Z' && F[i][j] >= 'A'){
F[i][j] = F[i][j] - 'A' + 'a';
}
}
for(int k = i + 1 ; k < 4 ; ++ k){
for(int v = 0 ; v < F[k].size() ; ++ v){
if(F[k][v] <= 'Z' && F[k][v] >= 'A'){
F[k][v] = F[k][v] - 'A' + 'a';
}
}
}
break;
}
}
int isfirst = 0;
for(int i = 1 ; i < 4 ; ++ i){
if(F[i].size()){
if(isfirst==0) isfirst = 1;
else cout << " ";
cout << F[i];
}
}
}
int main(int argc,char *argv[]){
// freopen("out.txt" , "w" , stdout );
getline(cin , base);
for(int i = 0 ; i < base.size() ; ++ i){
int j;
string temp;
for(j = i ; j < base.size() ; ++ j){
if( base[j] ==',' && i != j ) break;
temp.push_back( base[j] );
}
str.push_back( temp );
i = j - 1;
}
for(int i = 0 ; i < str.size() ; ++ i) Solve( str[i] , i );
cout << endl;
return 0;
}
URAL 1993 This cheeseburger you don't need 模拟题的更多相关文章
- ural 1993 This cheeseburger you don't need
顺次存到{} [] () 遇到逗号就处理下,最后处理逗号之后的 #include <iostream> #include <cstring> #include <stri ...
- URAL 2046 A - The First Day at School 模拟题
A - The First Day at SchoolTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudg ...
- ural 2032 Conspiracy Theory and Rebranding (数学水题)
ural 2032 Conspiracy Theory and Rebranding 链接:http://acm.timus.ru/problem.aspx?space=1&num=2032 ...
- Ural 1209. 1, 10, 100, 1000... 一道有趣的题
1209. 1, 10, 100, 1000... Time limit: 1.0 secondMemory limit: 64 MB Let's consider an infinite seque ...
- URAL 1519 Formula 1(插头DP,入门题)
Description Background Regardless of the fact, that Vologda could not get rights to hold the Winter ...
- ural 2020 Traffic Jam in Flower Town(模拟)
2020. Traffic Jam in Flower Town Time limit: 1.0 secondMemory limit: 64 MB Having returned from Sun ...
- ural 2015 Zhenya moves from the dormitory(模拟)
2015. Zhenya moves from the dormitory Time limit: 1.0 secondMemory limit: 64 MB After moving from hi ...
- Ural 1079 - Maximum
Consider the sequence of numbers ai, i = 0, 1, 2, …, which satisfies the following requirements: a0 ...
- bzoj AC倒序
Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...
随机推荐
- BERT(Bidirectional Encoder Representations from Transformers)理解
BERT的新语言表示模型,它代表Transformer的双向编码器表示.与最近的其他语言表示模型不同,BERT旨在通过联合调节所有层中的上下文来预先训练深度双向表示.因此,预训练的BERT表示可以通过 ...
- 关于U3D中的移动和旋转
关于移动,其实很简单,就是移动: 第一个参数标识移动的距离,是一个矢量:第二个参数是因为游戏对象有自己的坐标系,还有一个世界坐标系,使用的坐标系不同将导致运动的结果不同: function Trans ...
- 记一次测试环境下PXC集群问题《经验总结》
1.问题描述 当PXC集群节点全部宕机的,导致集群几点启动失败.报错导致无法启动 [ERROR] WSREP: It may not be safe to boo ...
- python基础(6)---set、collections介绍
1.set(集合) set和dict类似,也是一组key的集合,但不存储value.由于key不能重复,所以,在set中,没有重复的key. 集合和我们数学中集合的概念是一样的,也有交集.并集.差集. ...
- csu 1503: 点到圆弧的距离
1503: 点到圆弧的距离 Time Limit: 1 Sec Memory Limit: 128 MB Special JudgeSubmit: 614 Solved: 101[Submit] ...
- python datetime 时区(timezone) dateutil
记录下python中的时区问题, 代码如下: 包括datetime.datetime对象使用不同的时区,以及在不同时区间转换. from datetime import datetime from ...
- STM32 磁场传感器HMC5883
一.IIC协议 默认(出厂) HMC5883LL 7 位从机地址为0x3C 的写入操作,或0x3D 的读出操作. 要改变测量模式到连续测量模式,在通电时间后传送三个字节:0x3C 0x02 0x00 ...
- TPC-H数据导入MySQL教程
0. TPC-H是啥 TPC-H是TPC提供的一个benchmark,用来模拟一个现实中的商业应用,可以生成一堆虚构的数据,且自带一些查询,可以导入到各种数据库中来模拟现实需求,检查性能. 具体是怎样 ...
- c++ primer 9 顺序容器
定义: #include <vector> #include <list> #include <deque> vector<int> svec; lis ...
- 利用linux判断elf文件是64位还是32位
readelf 命令,参数为-h 例如 文件名为python >>>readelf -h python 得到的是ELF Header中的项Magic 第五个数 02时为64位,01时 ...