uva10602 - Editor Nottoobad
来源:互联网 发布:java 线程间通信 编辑:程序博客网 时间:2024/05/22 15:40
题意:
一台声控机子,有两条命令:— “repeat the last word”, “delete the last symbol”.给你一些单词,让你用合理运用这两条命令,最少的敲击键盘打出这些单词。
思路:
很简单的一道贪心,排序+比较即可。
代码如下:
#include <iostream>#include <cstdio>#include <cstring>#include <string>#include <algorithm>using namespace std;const int N = 105;int n;string str[N];int main() { int cas; scanf("%d", &cas); while (cas--) { scanf("%d", &n); for (int i = 0; i < n; i++) cin >> str[i]; sort(str, str + n); int cnt = str[0].size(); for (int i = 1; i < n; i++) { int len = str[i].size(); int j = 0; while (j < len&& (str[i][j]==str[i - 1][j])) j++; cnt += len - j; } printf("%d\n", cnt); for (int i = 0; i < n; i++) cout<< str[i]<<endl; } return 0;}
0 0
- uva10602 - Editor Nottoobad
- [贪心]UVA10602 Editor Nottoobad
- uva10602 - Editor Nottoobad
- uva10602 Editor Nottobad
- UVa 10602 - Editor Nottoobad
- UVa 10602 - Editor Nottoobad
- uva 10602 - Editor Nottoobad
- UVA 10602 - Editor Nottoobad
- UVA 10602 - Editor Nottoobad
- 10602 - Editor Nottoobad
- UVaOJ10602 - Editor Nottoobad
- uva 10602 Editor Nottoobad
- UVA 10602 EDITOR NOTTOOBAD
- Editor Nottoobad-10602
- UVa 10602 - Editor Nottoobad
- EDITOR NOTTOOBAD uva+贪心
- UVA - 10602 Editor Nottoobad
- UVA - 10602 Editor Nottoobad
- eclipse 快捷键
- pat1001:害死人不偿命的(3n+1)猜想
- MySQL启动远程连接
- Round robin
- 黑马程序员,未来的星星大牛的 基础java
- uva10602 - Editor Nottoobad
- Python内存管理机制
- 初次使用Android Studio的配置问题
- eclipse 导入XUtils 的 demo
- 一个师兄的面试经验,很诚恳
- lex和yacc 入门-- 计算器
- POJ1190
- javax.servlet.http.HttpSession session用法详解
- 网上找到的用xml传输图片