题目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,只能等下周答案出来了,看看别人的程序,再做修改。

 #include "iostream"
#include "string"
#include "vector" using namespace std; int main()
{
char s[];
bool point_tag = false; while (cin.getline(s, ))
{
int i = -,len;
vector<char> input; while (s[i++])
{
s[i] = tolower(s[i]);
}
len = i;
i = ;
s[i] = toupper(s[i]); for (int i = ; i < len; i++)
{
input.insert(input.begin() + i, s[i]);
} for (int i = ; i < input.size(); i++)
{
if (input[i] == ' ')
while (input[i + ] == ' ' || input[i + ] == ',')
{
if (input[i] == ',') {
input.insert(input.begin() + i + , ' ');
break;
} else
input.erase(input.begin() + i);
}
else if (input[i] == '.')
{
input.insert(input.begin() + i + , ' ');
char c = input[i + ];
c = toupper(c); input.erase(input.begin() + i + );
input.insert(input.begin() + i + , c);
}
} for (int i = ; i < input.size(); i++)
{
if (input[i] == '.')
{
char c = input[i + ];
c = toupper(c); input.erase(input.begin() + i + );
input.insert(input.begin() + i + , c);
}
cout << input[i];
}
cout << endl;
}
}

不能AC的痛!

hiho一下 第一百零七周 Give My Text Back(微软笔试题)的更多相关文章

  1. “全栈2019”Java第一百零七章:匿名内部类与构造方法注意事项

    难度 初级 学习时间 10分钟 适合人群 零基础 开发语言 Java 开发环境 JDK v11 IntelliJ IDEA v2018.3 文章原文链接 "全栈2019"Java第 ...

  2. 第一百零七节,JavaScript基本包装类型,数据类型的方法

    JavaScript基本包装类型,数据类型的方法 学习要点: 1.基本包装类型概述 2.Boolean类型 3.Number类型 4.String类型 为了便于操作基本类型值,ECMAScript提供 ...

  3. python第一百零七天-- Django 基础 2

    1.Django请求的生命周期 路由系统 -> 试图函数(获取模板+数据=>渲染) -> 字符串返回给用户 2.路由系统 /index/ -> 函数或类.as_view() / ...

  4. 【leetcode 简单】 第一百零七题 回旋镖的数量

    给定平面上 n 对不同的点,“回旋镖” 是由点表示的元组 (i, j, k) ,其中 i 和 j 之间的距离和 i 和 k 之间的距离相等(需要考虑元组的顺序). 找到所有回旋镖的数量.你可以假设 n ...

  5. 第一百零七篇:基本数据类型(undefined,null,boolean类型)

    好家伙, 本篇内容为<JS高级程序设计>第三章学习笔记 1.数据类型 ECMAScript有6种简单数据类型(称为原始类型): Undefined, Null, Boolean, Numb ...

  6. “全栈2019”Java第一百零六章:匿名内部类与抽象类接口注意事项

    难度 初级 学习时间 10分钟 适合人群 零基础 开发语言 Java 开发环境 JDK v11 IntelliJ IDEA v2018.3 文章原文链接 "全栈2019"Java第 ...

  7. “全栈2019”Java第一百零九章:匿名内部类实现唯一抽象类或接口

    难度 初级 学习时间 10分钟 适合人群 零基础 开发语言 Java 开发环境 JDK v11 IntelliJ IDEA v2018.3 文章原文链接 "全栈2019"Java第 ...

  8. “全栈2019”Java第一百零五章:匿名内部类覆盖作用域成员详解

    难度 初级 学习时间 10分钟 适合人群 零基础 开发语言 Java 开发环境 JDK v11 IntelliJ IDEA v2018.3 文章原文链接 "全栈2019"Java第 ...

  9. “全栈2019”Java第一百零四章:匿名内部类与外部成员互访详解

    难度 初级 学习时间 10分钟 适合人群 零基础 开发语言 Java 开发环境 JDK v11 IntelliJ IDEA v2018.3 文章原文链接 "全栈2019"Java第 ...

随机推荐

  1. git 推送

    echo "# shops" >> README.md git init git add README.md git commit -m "first com ...

  2. 自然语言18_Named-entity recognition

    https://en.wikipedia.org/wiki/Named-entity_recognition http://book.51cto.com/art/201107/276852.htm 命 ...

  3. 有关stdint.h 文件

    有关stdint.h 文件 Google C++编程规范的P25页有如下叙述: <stdint.h> 定义了 int16_t . uint32_t . int64_t 等整型,在需要确定大 ...

  4. 第2章 jQuery的选择器

    选择器是jQuery的根基 一. 认识 1.CSS常用的选择器 标签选择器,后代选择器,Id选择器,通配符选择器,类选择器,群组选择器——主流浏览器全部支持 伪类选择器,子选择器,临近选择器等等——不 ...

  5. ViewController respondsToSelector:]: message sent to deallocated instance

    今天突然遇到这个问题,其实昨天下班的时候就已经有这个问题了, 就是先进入一个画页,然后再快速离开这个画页再进入其他画页就出现这个错误 了 找了好久也没有找出问题来,一开始以为是网络任务没有cancel ...

  6. Python之路【第六篇】:面向对象编程相关

    判断类与对象关系 isinstance(obj, cls)  判断对象obj是否是由cls类创建的 #!/usr/bin/env python #-*- coding:utf-8 -*- class ...

  7. Python之路【第五篇续】:面向对象编程二

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABgQAAALaCAIAAABxja8cAAAgAElEQVR4nOzd6X9Tdd74/+uv+f5uzF

  8. IE禁用Cookie后的session处理

    IE禁用Cookie后解决方案:URL重写 购物车案例<IE禁用Cookie后> 购物界面ShowBook.servlet public void doGet(HttpServletReq ...

  9. mysql主从复制(超简单)

      mysql主从复制(超简单) 怎么安装mysql数据库,这里不说了,只说它的主从复制,步骤如下: 1.主从服务器分别作以下操作:  1.1.版本一致  1.2.初始化表,并在后台启动mysql  ...

  10. 【转】apache kafka监控系列-KafkaOffsetMonitor

    apache kafka监控系列-KafkaOffsetMonitor 时间 2014-05-27 18:15:01  CSDN博客 原文  http://blog.csdn.net/lizhitao ...