HNUSTOJ 1601:名字缩写
1601: 名字缩写
时间限制: 1 Sec 内存限制: 128 MB
提交: 288 解决: 80
[提交][状态][讨论版]
题目描述
Noname老师有一个班的学生名字要写,但是他太懒了,想少写几个字母。很快他发现这是可行的,例如下面的学生名单:
输入
给定一系列名字,每个名字一行(不超过100行),名字仅含英文字母,名字长度不超过40,这些名字按字母升序排列, 任意两个名字不相同而且一个名字不会正好是另一个名字的前缀。
输出
每行输入对应一行输出,内容为空格分开原来的名字和缩写后的名字。
样例输入
Adams
Andersen
Anderson
Carson
Carter
Carville
Cooper
Coply
Smith
Smythe
Sorensen
Sorenson
Wynn
样例输出
Adams Ad
Andersen Anderse
Anderson Anderso
Carson Cars
Carter Cart
Carville Carv
Cooper Coo
Coply Cop
Smith Smi
Smythe Smy
Sorensen Sorense
Sorenson Sorenso
Wynn W
提示
来源
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
#include<iostream> #include<cstring> #include<cstdio> #include<string> #include<map> using namespace std; const int N = 100 + 5; char name[N][45]; map<string, int > mp; void Add( char *ch){ int len = strlen (ch); for ( int i=1;i<= len;i++){ char c = ch[i]; ch[i] = '\0' ; mp[ch]++; ch[i] = c; } } void solve( int x){ char ch[45]; strcpy (ch,name[x]); int len = strlen (ch); for ( int i=1;i<=len;i++){ char c = ch[i]; ch[i] = '\0' ; if (mp[ch]==1){ printf ( "%s %s\n" ,name[x],ch); return ;} ch[i] = c; } } int main(){ std::ios::sync_with_stdio( false ); int cnt = 0; while ( scanf ( "%s" ,name[cnt])==1){ Add(name[cnt++]); } for ( int i=0;i<cnt;i++){ solve(i); } } |
HNUSTOJ 1601:名字缩写的更多相关文章
- 应用程序框架实战十一:创建VS解决方案与程序集
上一篇,介绍了开发环境需要的工具和版本,本篇将动手创建VS解决方案. 对于本系列文章提供的示例,我想通过两种途径来演示,一种是单元测试,另外为了能更直观的看到效果,还会提供一个用户界面来展示.为了不分 ...
- php版本历史
php最初就是为了快速构建一个web页面而迅速被大家广为接受的.它的好处是在代码中能内嵌html的代码,从而让程序员能再一个页面中同时写html代码和php代码就能生成一个web页面. 这篇文章用时间 ...
- css/js(工作中遇到的问题)
移动设备点击时去掉外加的蓝色边框 a, input, button { -webkit-tap-highlight-color: rgba(0,0,0,0); -webkit-tap-highligh ...
- iOS时间那点事儿–NSTimeZone
NSTimeZone **时区是一个地理名字,是为了克服各个地区或国家之间在使用时间上的混乱. 基本概念: GMT 0:00 格林威治标准时间; UTC +00:00 校准的全球时间; CCD +08 ...
- iOS 时间处理(转)
NSDate NSDate对象用来表示一个具体的时间点. NSDate是一个类簇,我们所使用的NSDate对象,都是NSDate的私有子类的实体. NSDate存储的是GMT时间,使用的时候会根据 当 ...
- 电影TS、TC、SCR、R5、BD、HD等版本是什么意思
在很多电影下载网站的影片标题中我们都能看到,比如<刺杀希特勒BD版>.<游龙戏凤TS版>等,这些英文缩写都是什么意思呢?都代表什么画质?以下就是各个版本的具体含义: 1.CAM ...
- [microsoft]PE和COFF文件格式
前言 我们知道,vs的C/C++编译工具把每一个编译单元(一个.c或.cpp源文件)编译成一个对象文件(.obj文件):然后用链接器把这些对象文件组合一个单个文件(.exe文件),称为可移植的可执行文 ...
- 越狱Season 1-Episode 1: the pilot
the pilot: 美国电视剧新剧开播都会有一个试播来测试观众对新剧的接受程度,以此来决定是否再继续播下去,也可以说是一个开端,第一集,试播 -Tattoo Artist: That's it. t ...
- nagios plugin 开发
https://nagios-plugins.org/doc/guidelines.html#DEVREQUIREMENTS https://blog.centreon.com/good-practi ...
随机推荐
- DevExpress.XtraGrid.Views.Grid.GridView
private void SetView() { GridView gridView = (GridView)this.DefaultView; if (gridView != null) { gri ...
- 模板_BIT
#include<bits/stdc++.h> #define maxn 500005 //#define int long long using namespace std; inlin ...
- mini-batch
我们在训练神经网络模型时,最常用的就是梯度下降,梯度下降有一下几种方式: 1.Batch gradient descent(BGD批梯度下降) 遍历全部数据集算一次损失函数,然后算函数对各个参数的梯度 ...
- 【canvas学习笔记三】样式和颜色
上一节我们学习了如何用路径绘制各种形状,但我们只能用默认的颜色和线条.这节就来学习设置不同的颜色和线条样式. 颜色 设置颜色主要有两个属性: fillStyle = color 设置填充颜色 stro ...
- Spring Data Jpa (二)JPA基础查询
介绍Spring Data Common里面的公用基本方法 (1)Spring Data Common的Repository Repository位于Spring Data Common的lib里面, ...
- formData和input的file结合使用
<form method="POST" id="uploadForm" enctype="multipart/form-data"&g ...
- LeetCode_1116.打印零与奇偶数(多线程)
LeetCode_1116 LeetCode-1116.打印零与奇偶数 假设有这么一个类: class ZeroEvenOdd { public ZeroEvenOdd(int n) { ... } ...
- 将Windows下的文件同步到Linux下
需求:把Windows下的某些文件自动传送到Linux指定目录下 实现: 1. Windows下安装 WinSCP工具,并把Liunx服务器信息保存 2. 编写脚本,实现双击工具就把Windows下的 ...
- qemu-kvm: unable to map backing store for guest RAM: Cannot allocate memory
当给 KVM 虚拟机设置 hugepage 时,需要在虚拟机的配置文件里加上下面一段: <memoryBacking> <hugepages/></memoryBacki ...
- 【MAC】 命令行解压缩 rar 文件
使用Mac解压rar文件很简单,总共分2步.step1:安装解压工具,step2:解压 1.使用Homebrew安装unrar brew install unrar 2.cd到rar文件的目录下,然后 ...