uva10602 - Editor Nottoobad
2016-03-05 12:22
197 查看
题意:
一台声控机子,有两条命令:— “repeat the last word”, “delete the last symbol”.给你一些单词,让你用合理运用这两条命令,最少的敲击键盘打出这些单词。
思路:
很简单的一道贪心,排序+比较即可。
代码如下:
一台声控机子,有两条命令:— “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 ; 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; }
相关文章推荐
- 关于自适应网站的总结
- JS面向对象组件(六) -- 拖拽功能以及组件的延展
- swift 调用第三方的oc 方法
- eclipse 快捷键
- leetcode:Two Sum 【Java】
- elasticsearch小记之—— unmapped_type的使用
- HDU 1535 SPFA 前向星存图优化
- 结转时数据进一步修正
- Redis 入门学习时不理解的问题
- 管理2
- p68 对数变换 关于fft2 fftshift 频谱
- Spring boot app动态更新数据库表
- eclipse中查看Android源代码
- C++ 17 的最新动态
- uva607
- 深入研究java.lang.Class类
- oracle插入特殊字符'&'问题
- 数据结构——算法之(010)( 字符串的左旋转操作)
- An error I have completed recently
- XML和JSon数据的解析