博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hiho一下 第一百零七周 Give My Text Back(微软笔试题)
阅读量:4346 次
发布时间:2019-06-07

本文共 3569 字,大约阅读时间需要 11 分钟。

题目1 : Give My Text Back

时间限制:10000ms
单点时限:1000ms
内存限制:256MB

描述

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.

题目大意

小Hi和小Ho为了准备英语的期末考试,找了很多英语的电子资料。但是由于U盘出了问题,导致资料内容变得很乱。于是小Hi和小Ho决定写一个程序去将所有的电子资料格式化。 已知每一份资料只包含大小写字母,‘ ’(空格), ‘,’(逗号),‘.’(句号)以及换行符。小Hi和小Ho希望整理后的资料为如下格式: - 每一句话都是以’.’结尾,每一段话都是以换行符结尾。 - 每一段开始没有空格。 - 每一个句子都是完整的,即至少包含1个单词,句末一定为‘.’(句号)。 - 每一句话只有首字母大写。 - 每句话内单词之间由1个空格隔开。 - 标点符号与前面的单词之间无空格,标点符号后有1个空格或换行符。 对于给定的资料,请你对其进行格式化,并输出格式化的结果。

 

解题思路:

讲每行输入的数据先全部小写化处理,然后检测,空格,连续的空格就行删除,只留一个,逗号和句号后面加空格,因为需要对数组进行直接插入删除操作,所以用vector<char>,,,为什么不用list,因为list链表分配的不是连续的地址,不能通过下标直接存取。代码本地通过了,不过,提交没有AC,只能等下周答案出来了,看看别人的程序,再做修改。

 

1 #include "iostream" 2 #include "string" 3 #include "vector" 4  5 using namespace std; 6  7 int main() 8 { 9     char s[10000];10     bool point_tag = false;11 12     while (cin.getline(s, 10000))13     {14         int i = -1,len;15         vector
input; 16 17 while (s[i++])18 {19 s[i] = tolower(s[i]);20 }21 len = i;22 i = 0;23 s[i] = toupper(s[i]);24 25 for (int i = 0; i < len; i++)26 {27 input.insert(input.begin() + i, s[i]);28 }29 30 for (int i = 0; i < input.size(); i++)31 {32 if (input[i] == ' ')33 while (input[i + 1] == ' ' || input[i + 1] == ',')34 {35 if (input[i] == ',') {36 input.insert(input.begin() + i + 1, ' ');37 break;38 }39 40 else41 input.erase(input.begin() + i);42 } 43 else if (input[i] == '.')44 {45 input.insert(input.begin() + i + 1, ' ');46 char c = input[i + 2];47 c = toupper(c);48 49 input.erase(input.begin() + i + 2);50 input.insert(input.begin() + i + 2, c);51 } 52 }53 54 for (int i = 0; i < input.size(); i++)55 {56 if (input[i] == '.')57 {58 char c = input[i + 2];59 c = toupper(c);60 61 input.erase(input.begin() + i + 2);62 input.insert(input.begin() + i + 2, c);63 }64 cout << input[i];65 } 66 cout << endl;67 }68 }

不能AC的痛!

 

转载于:https://www.cnblogs.com/SeekHit/p/5688638.html

你可能感兴趣的文章
二维数组中的查找
查看>>
java面向对象基础总结
查看>>
java第一次实验总结&第三周总结
查看>>
第四周总结&第二次实验报告
查看>>
AlwaysOn 执行备份任务
查看>>
Jenkins构建基于.NET Framework的web程序
查看>>
Jenkins构建基于.NET Core的web程序
查看>>
为什么要用Kubernetes?
查看>>
kubernetes实战(二十六):kubeadm 安装 高可用 k8s 1.16.x dashboard 2.x
查看>>
《博客园美化》添加雪花/修改icon
查看>>
JS对比时间大小
查看>>
《ECharts》ECharts学习日记
查看>>
《H5 App开发》安卓安装最新版本失败
查看>>
js获取开始年与结束年之间的年份
查看>>
《VUE》vue使用echarts
查看>>
《博客园美化》鼠标点击特效
查看>>
《VUE》学习日志
查看>>
《博客园美化》为您的博客增加一个萌萌的看板娘吧
查看>>
《VUE》vue 路由传参的三种基本模式
查看>>
《VUE》搜索关键字高亮显示
查看>>