UVA - 10602 Editor Nottoobad
来源:互联网 发布:淘宝同学app 编辑:程序博客网 时间:2024/06/04 17:40
题目大意:要输入 n 个单词,现在有三种操作, 1、输入一个字符,需要按下一次按键。 2、通过声控删除一个字符。3、通过声控复制一遍上面的单词。现在要求按最少的按键来完成输入,并且输出输入的顺序。
解题思路:因为有复制这一功能,所以每次输入一个单词之后要找另一个与它相似度最近的一个。比较两个单词对应的不同字符个数,对于两个不同长度的单词,后面的单词长的话要计算多出的部分,因为是再输入的,要是短的话就不需要计算,因为是通过声控删除的。
#include <iostream>#include <algorithm>#include <string>using namespace std;int main() {int T;cin >> T;string s[105];while (T--) {int n;cin >> n;for (int i = 0; i < n; i++)cin >> s[i];sort(s, s + n);int sum = s[0].size();for (int i = 1, cnt; i < n; i++) {for (cnt = 0; s[i][cnt] && s[i-1][cnt] && s[i][cnt] == s[i-1][cnt]; cnt++);sum += s[i].length() - cnt;}cout << sum << endl;for (int i = 0; i < n; i++)cout << s[i] << endl;}return 0;}
0 0
- UVa 10602 - Editor Nottoobad
- UVa 10602 - Editor Nottoobad
- uva 10602 - Editor Nottoobad
- UVA 10602 - Editor Nottoobad
- UVA 10602 - Editor Nottoobad
- uva 10602 Editor Nottoobad
- UVA 10602 EDITOR NOTTOOBAD
- UVa 10602 - Editor Nottoobad
- UVA - 10602 Editor Nottoobad
- UVA - 10602 Editor Nottoobad
- uva 10602 Editor Nottoobad
- UVA 10602 - Editor Nottoobad
- UVA - 10602 Editor Nottoobad
- uva 10602 Editor Nottoobad(排序)
- EDITOR NOTTOOBAD - UVa 10602 贪心
- UVA 10602 Editor Nottoobad(贪心)
- UVa 10602 Editor Nottoobad (等价转换思想)
- uva - 10602 - Editor Nottoobad(贪心)
- 上海二手挖掘机市场,二手挖掘机价格优惠
- 很久没回来写博客了。
- ubuntu server设置时区和更新时间
- #pragma once 与 #ifndef 解析
- 织梦dedecms网站六大SEO优化技巧分享
- UVA - 10602 Editor Nottoobad
- OpenMP 作业
- Android USB tethering相关代码
- Spring4、SpringMVC4、Jackson2、Hibernate4、Quartz2、Plupload2、Proxool0.9集成
- 第7周 项目4 “撞错”体验
- dede自动采集自动伪原创完美版插件 元旦优惠活动
- SCI是什么
- java电影网站开发经验2
- Action中匹配多个方法使用(通配符*) <action name="role_*" class="roleAction" method="{1}">