POJ 1002 487-3279
来源:互联网 发布:java微信支付回调demo 编辑:程序博客网 时间:2024/06/05 21:52
这道题的思路是:
首先利用char map[] = "2223334445556667-77888999-"; //ABCDEFGHIJKLMNOPQRSTUVWXYZ 对数据进行转换,转换之后的数据只包含-和数字,然后去掉字符串中的-,并重新添加上‘-’。最后排序,统计字符串的数据。
#include <iostream>#include <cstdio>#include <vector>#include <string>#include <functional>#include <algorithm>using namespace std;char map[] = "2223334445556667#77888999#"; //ABCDEFGHIJKLMNOPQRSTUVWXYZvoid visited(char &ch) // visit and format strings{ if (ch >= 'A' && ch <= 'Z') ch=map[ch-'A']; // ch equals to its real number}void replace_m( string &s){ string::iterator it = s.begin(); for (; it != s.end(); it ++) { if (*it <='P' && *it >= 'A') { *it = '2'+(*it-'A')/3; } else if(*it >'P' && *it < 'Z') { *it = '7'+(*it-'Q')/3; } }}int main (){ //freopen("1.txt","r",stdin); int num = 0; cin >> num; vector<string> svec; int cts = 0; string inpts; { while (num --) { cin >> inpts; inpts.erase(remove_if(inpts.begin(),inpts.end(),bind2nd(equal_to<char>(),'-')),inpts.end()); inpts.erase(remove_if(inpts.begin(),inpts.end(),bind2nd(equal_to<char>(),'Q')),inpts.end()); inpts.erase(remove_if(inpts.begin(),inpts.end(),bind2nd(equal_to<char>(),'Z')),inpts.end()); replace_m(inpts); svec.push_back(inpts); } sort (svec.begin(),svec.end()); string ss = *(svec.begin()); vector<string>::iterator it = svec.begin(); ++it; int sct = 1; int flag = 0; int tamp = 0; for (; it != svec.end(); it ++) { if (!ss.compare(*it)) { sct ++; tamp = 1; } else { if(sct >=2) { ss.insert(3,"-"); flag = 1; cout << ss <<' ' << sct <<endl; tamp = 0; } sct = 1; ss = *it; } } if(tamp && sct>=2) { ss.insert(3,"-"); flag = 1; cout << ss <<' ' << sct <<endl; tamp = 0; } if(!flag) cout<<"No duplicates."<<endl; }}
这道题木在最后输出的时候,由于统计的时候考虑疏忽,当num=2的时候,出现错误。
- POJ--1002 487-3279
- POJ 1002 487-3279
- POJ 1002 487-3279
- POJ 1002 487-3279
- poj 1002 "487-3279"
- POJ 1002 487-3279
- poj 1002 487-3279
- poj 1002 487-3279
- POJ-1002 487-3279
- poj 1002 487-3279
- POJ 1002 487-3279
- poj 1002 487-3279
- (POJ 1002) 487-3279
- POJ 1002 487-3279
- POJ 1002 487-3279
- [POJ]1002 487-3279
- POJ 1002 487-3279
- poj 1002 487-3279
- wikioi 3116 高精度练习之加法
- 以面到点的学习MFC
- DEDECMS分页标签及分页样式通用代码
- Linux下Squid配置详解 Squid代理服务器配置
- 5天学会jaxws-webservice编程第二天
- POJ 1002 487-3279
- linux中的查找
- dedecms 列表页标题title后加上页数的方法
- iOS 单元测试
- HTML那点事之【文本格式化】(转载)
- 调试&PDB
- struts2上传文件容易疏忽的地方
- socekt recv返回值
- apxs - apache扩展工具编译命令解析