POJ1002
来源:互联网 发布:用户积分数据库设计 编辑:程序博客网 时间:2024/06/03 17:47
POJ1002 – 真·水题(个鬼)
这里吐槽一下POJ的g++,同一段代码用c++能过g++过不了
然后再吐槽一下这一题的那个No duplicates.
,也不清楚到底要不要给句号(事实证明要)
然后数据里面竟然会有0开头的。。。这个wa的我一脸懵逼,最后网上找到了测试数据才发现错在哪里
注:%03d
这个制表符可以右对齐然后自动补零
这题我用数组排序做的,用map做也可以,不过弱还不会用map,然后由于数比较小最大只有10000000,因此也可以开大一点的数组直接存不用排序
贴一下代码
#include <iostream>#include <string>#include <cstdio>#include <vector>#include <algorithm>using namespace std;vector <int> telephone;string s;void handle(string s);bool comparison(int a, int b);void output();void input();int main(){ input(); sort(telephone.begin(), telephone.end(), comparison); output(); return 0;}bool comparison(int a, int b){ return (a < b);}void output(){ int t = 1; bool h = 0; telephone.push_back(-1); for (int i = 1; i < telephone.size(); i++) { if (telephone[i] == telephone[i - 1]) t++; else { if (t > 1) { printf("%03d-%04d %d\n", telephone[i - 1] / 10000, telephone[i - 1] % 10000, t); t = 1; h = 1; } } } if (!h) cout << "No duplicates." << endl; telephone.pop_back();}void input(){ int n; cin >> n; for (int i = 0; i < n; i++) { cin >> s; handle(s); }}void handle(string s){ int t = 0; char c; for (int i = 0; i < s.size(); i++) { c = s[i]; if (c == '-') ; else if (c >= '0' && c <= '9') t = t * 10 + c - '0'; else if (c >= 'A' && c < 'Q') t = t * 10 + (c - 'A') / 3 + 2; else if (c > 'Q' && c < 'Z') t = t * 10 + (c - 'A' - 1) / 3 + 2; } telephone.push_back(t);}
0 0
- POJ1002
- POJ1002
- poj1002
- poj1002
- poj1002
- poj1002
- poj1002
- POJ1002
- poj1002
- POJ1002
- POJ1002
- POJ1002
- poj1002
- POJ1002
- POJ1002
- poj1002
- poj1002
- POJ1002
- 最大连续数列的和
- 教你制作表格样式的ListView
- 激光雷达知名供应商 你知道几家?
- Windows平台下安装Eclipse插件,开发Hadoop应用
- gcc的__builtin_函数介绍
- POJ1002
- iOS 开发之多线程GCD介绍
- (第1篇)什么是hadoop大数据?我又为什么要写这篇文章?
- 机器学习: TensorFlow 的数据读取与TFRecords 格式
- 信安实验-RC4加密算法
- idea 创建多模块依赖Maven项目
- htop 详解
- Linuxshell编程之变量
- AJAX+SpringMVC 获取后台数据的方式