标签:des style os strong io for art cti
题目如下:
This cheeseburger you don‘t need
Description
Input
Output
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;
}
标签:des style os strong io for art cti
原文地址:http://www.cnblogs.com/famousli/p/3874676.html