POJ - 1002 487-3279
2016-02-24 19:56
381 查看
1.题面
http://poj.org/problem?id=10022.解题思路
这道题目我是做过的,这次居然没做出来,天哪,好像是因为人太困了写的时候出现了无数个BUG,比如在嵌套的循环中两层for都使用了i作为变量然后,这道题目并不难,只是有些繁琐,做好了字母到数字之间的映射之后,要么讲将这个只有7位数的数字转化成一个int存储,要么将它用string存储
之后爱用map用map,爱用排序后计数就用排序后计数,有的是办法。
3.解题代码
/***************************************************************** > File Name: tmp.cpp > Author: Uncle_Sugar > Mail: uncle_sugar@qq.com > Created Time: 2016年02月24日 星期三 09时43分05秒 ****************************************************************/ # include <cstdio> # include <cstring> # include <cmath> # include <cstdlib> # include <climits> # include <iostream> # include <iomanip> # include <set> # include <map> # include <vector> # include <stack> # include <queue> # include <algorithm> using namespace std; const int debug = 1; const int size = 5000 + 10; typedef long long ll; char str[size],nstr[size]; map<string,int> mp; int charmap[500]; int main() { std::ios::sync_with_stdio(false);cin.tie(0); charmap['A'] = charmap['B'] = charmap['C'] = 2; charmap['D'] = charmap['E'] = charmap['F'] = 3; charmap['G'] = charmap['H'] = charmap['I'] = 4; charmap['J'] = charmap['K'] = charmap['L'] = 5; charmap['M'] = charmap['N'] = charmap['O'] = 6; charmap['P'] = charmap['R'] = charmap['S'] = 7; charmap['T'] = charmap['U'] = charmap['V'] = 8; charmap['W'] = charmap['X'] = charmap['Y'] = 9; int i,j,k; int n; cin >> n; while(n--){ cin >> str; for (k=i=0;str[i]!='\0';i++){ if (isupper(str[i])){ nstr[k++] = charmap[str[i]] + '0'; }else if (isdigit(str[i])){ nstr[k++] = str[i]; } if (k==3) nstr[k++] = '-'; } nstr[k] = '\0'; mp[nstr]++; } int flag = 1; map<string,int>::iterator it; for (it=mp.begin();it!=mp.end();it++){ if (it->second>=2){ flag = 0; cout << it->first << ' ' << it->second << '\n'; } } if (flag) cout << "No duplicates." << '\n'; return 0; }
相关文章推荐
- 正式生产环境下hadoop集群的DNS+NFS+ssh免password登陆配置
- 简单的多线程(活用OD解决运行时错误)
- gpt 分区做xfs系统简介
- Androidx学习笔记(71)--- 需要支付的应用(调用远程的服务)
- Kubernetes基本术语与架构
- linux环境下部署tomcat工程,日志不走log4j配置而打印到catalina.out可能的原因
- android的进阶findViewById
- 抽象之美
- Server Tomcat v7.0 Server at localhost was unable to start within 45 seconds错误
- JDK安装与环境变量配置
- 类名与需要导入的类的名称重复出错
- 如何解决Android 5.0中出现的警告: Service Intent must be explicit:
- SCOI2009[游戏] dp
- RecyclerView详解 —— 自定义动画
- java调用usb摄像头
- iOS中的应用启动原理
- nginx介绍和常见应用
- 使用线程进行网络图片下载(一)
- [工作代码]dom4j解析实例
- PAT-1021 个位数统计