#1197 : Give My Text Back
2018-03-19 23:27
316 查看
时间限制:10000ms单点时限:1000ms内存限制:256MB
先把所有字母变成小写,空格去掉,在进行输出,增加大写字母的操作。
代码:#include <bits/stdc++.h>
using namespace std;
/*
97 122
65 90
*/
int main()
{
string a;
string b;
while(getline(cin,a))
{
b="";
int l=a.size();
for(int i=0;i<l;i++)
{
if(a[i]>='A'&&a[i]<='Z')
{
b+=(a[i]+32);
}
else
{
if(a[i]==' '&&a[i+1]==' ')continue;
if(a[i]==' '&&a[i+1]==',')continue;
if(a[i]==' '&&a[i+1]=='.')continue;
if(a[i]==','&&a[i+1]!=' ')
{
b+=a[i];
b+=' ';
continue;
}
if(a[i]=='.'&&a[i+1]!=' ')
{
b+=a[i];
b+=' ';
continue;
}
b+=a[i];
}
}
int le=b.size();
int ju=1;
for(int i=0;i<le;i++)
{
if(b[i]=='.')
{
ju=1;
continue;
}
if(ju)
{
if(b[i]>='a'&&b[i]<='z')
{
b[i]=b[i]-32;
ju=0;
}
}
}
cout<<b<<endl;
}
return 0;
}
描述
To prepare for the English exam Little Ho collected many digital reading materials. Unfortunately the materials are messed up by a malware.It is known that the original text contains only English letters (a-zA-Z), spaces, commas, periods and newlines, conforming to the following format:1. Each sentence contains at least one word, begins with a letter and ends with a period.2. In a sentence the only capitalized letter is the first letter.3. In a sentence the words are separated by a single space or a comma and a space.4. The sentences are separated by a single space or a single newline.It is also known the malware changes the text in the following ways:1. Changing the cases of letters.2. Adding spaces between words and punctuations.Given the messed text, can you help Little Ho restore the original text?输入
A string containing no more than 8192 English letters (a-zA-Z), spaces, commas, periods and newlines which is the messed text.输出
The original text.样例输入my Name is Little Hi. His name IS Little ho , We are friends.样例输出
My name is little hi. His name is little ho, we are friends.这道题虽然只是个简单的模拟就可以。但是弄的我很惨,发下来,做个几年教训,以后遇到细节的希望能写好。
先把所有字母变成小写,空格去掉,在进行输出,增加大写字母的操作。
代码:#include <bits/stdc++.h>
using namespace std;
/*
97 122
65 90
*/
int main()
{
string a;
string b;
while(getline(cin,a))
{
b="";
int l=a.size();
for(int i=0;i<l;i++)
{
if(a[i]>='A'&&a[i]<='Z')
{
b+=(a[i]+32);
}
else
{
if(a[i]==' '&&a[i+1]==' ')continue;
if(a[i]==' '&&a[i+1]==',')continue;
if(a[i]==' '&&a[i+1]=='.')continue;
if(a[i]==','&&a[i+1]!=' ')
{
b+=a[i];
b+=' ';
continue;
}
if(a[i]=='.'&&a[i+1]!=' ')
{
b+=a[i];
b+=' ';
continue;
}
b+=a[i];
}
}
int le=b.size();
int ju=1;
for(int i=0;i<le;i++)
{
if(b[i]=='.')
{
ju=1;
continue;
}
if(ju)
{
if(b[i]>='a'&&b[i]<='z')
{
b[i]=b[i]-32;
ju=0;
}
}
}
cout<<b<<endl;
}
return 0;
}
相关文章推荐
- hihocoder 1197 Give My Text Back
- hiho一下第107周《Give My Text Back》
- hihocoder:Give My Text Back
- Give My Text Back
- Give My Text Back_hihoCoder
- [2016 微软预科生计划-探星夏令营在线测试2] Give My Text Back(字符串处理)
- 微软笔试题 《Give My Text Back》
- hihocoder 1197 : Give My Text Back
- hihocoder 1197 Give My Text Back
- # hihocoder #1197 : Give My Text Back
- hihoCoder #1197 Give My Text Back
- Give Me Back My Digital Rights!
- android学习之LayoutInflater的用法,在myAdapter getView()里将多个TextView组件压缩成一个View控件,并在listView里显示
- A Tool to Convert Binary to Text File and Convert Back
- Give my best wishes to you in Thanksgiving Day!
- Fragment EditText back 自动覆盖所有
- Can you give a visual explanation for the back propagation algorithm for neural networks?
- Give my best wishes to you in Thanksgiving Day!
- <转>My sublime text (Windows) cheat sheet
- Why do my text files suddenly have an additional at the end of each line?