PKU ACM 1002 487-3279 C++实现
来源:互联网 发布:石柱农村淘宝招聘 编辑:程序博客网 时间:2024/05/17 03:51
#include <iostream>
#include <map>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
class LiQiang
{
private:
inline char convert(char ch)
{
if (ch <= '9' && ch >= '0')
{
return ch;
}
if ('A' == ch || 'B' == ch || 'C' == ch)
return '2';
if ('D' == ch || 'E' == ch || 'F' == ch)
return '3';
if ('G' == ch || 'H' == ch || 'I' == ch)
return '4';
if ('J' == ch || 'K' == ch || 'L' == ch)
return '5';
if ('M' == ch || 'N' == ch || 'O' == ch)
return '6';
if ('P' == ch || 'R' == ch || 'S' == ch)
return '7';
if ('T' == ch || 'U' == ch || 'V' == ch)
return '8';
if ('W' == ch || 'X' == ch || 'Y' == ch)
return '9';
return '-';
}
static int cmp(pair<string, int> & x, pair<string, int> & y)
{
return x.second < y.second;
}
map<string, int> m_map;
vector<pair<string, int> > m_vector;
int num;
public:
LiQiang()
{
num = 0;
}
void add(string str)
{
num++;
string::iterator itor_str = str.begin();
for (; itor_str != str.end(); itor_str++)
{
while ( itor_str != str.end() && '-' == convert(*itor_str))
{
itor_str = str.erase(itor_str);
}
if (itor_str != str.end())
{
*itor_str = convert(*itor_str);
}
else
{
break;
}
}
str.insert(3, 1, '-');
map<string, int>::iterator itor_map;
itor_map = m_map.find(str);
if (m_map.end() == itor_map)
{
m_map[str] = 1;
} else
{
itor_map->second++;
}
}
void qsort()
{
map<string, int>::iterator itor_map = m_map.begin();
for (; itor_map!=m_map.end(); itor_map++)
{
m_vector.push_back(make_pair(itor_map->first, itor_map->second));
}
sort(m_vector.begin(), m_vector.end(), cmp);
}
friend ostream & operator << (ostream & os, LiQiang &tmp);
};
ostream & operator << (ostream & os, LiQiang &tmp)
{
if (tmp.num == tmp.m_map.size())
{
os << "No duplicates." << endl;
}
else
{
map<string, int>::iterator itor = tmp.m_map.begin();
for (; itor != tmp.m_map.end(); itor++)
{
if (1 == itor->second)
{
continue;
}
else
{
os << itor->first << " " << itor->second << endl;
}
}
}
return os;
}
int main()
{
string str;
char tmp[100];
int num;
LiQiang res;
scanf("%d", &num);
for (int i = 0; i < num; i++)
{
scanf("%s", tmp);
str = tmp;
res.add(str);
}
cout << res;
system("PAUSE");
return 0;
}
#include <map>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
class LiQiang
{
private:
inline char convert(char ch)
{
if (ch <= '9' && ch >= '0')
{
return ch;
}
if ('A' == ch || 'B' == ch || 'C' == ch)
return '2';
if ('D' == ch || 'E' == ch || 'F' == ch)
return '3';
if ('G' == ch || 'H' == ch || 'I' == ch)
return '4';
if ('J' == ch || 'K' == ch || 'L' == ch)
return '5';
if ('M' == ch || 'N' == ch || 'O' == ch)
return '6';
if ('P' == ch || 'R' == ch || 'S' == ch)
return '7';
if ('T' == ch || 'U' == ch || 'V' == ch)
return '8';
if ('W' == ch || 'X' == ch || 'Y' == ch)
return '9';
return '-';
}
static int cmp(pair<string, int> & x, pair<string, int> & y)
{
return x.second < y.second;
}
map<string, int> m_map;
vector<pair<string, int> > m_vector;
int num;
public:
LiQiang()
{
num = 0;
}
void add(string str)
{
num++;
string::iterator itor_str = str.begin();
for (; itor_str != str.end(); itor_str++)
{
while ( itor_str != str.end() && '-' == convert(*itor_str))
{
itor_str = str.erase(itor_str);
}
if (itor_str != str.end())
{
*itor_str = convert(*itor_str);
}
else
{
break;
}
}
str.insert(3, 1, '-');
map<string, int>::iterator itor_map;
itor_map = m_map.find(str);
if (m_map.end() == itor_map)
{
m_map[str] = 1;
} else
{
itor_map->second++;
}
}
void qsort()
{
map<string, int>::iterator itor_map = m_map.begin();
for (; itor_map!=m_map.end(); itor_map++)
{
m_vector.push_back(make_pair(itor_map->first, itor_map->second));
}
sort(m_vector.begin(), m_vector.end(), cmp);
}
friend ostream & operator << (ostream & os, LiQiang &tmp);
};
ostream & operator << (ostream & os, LiQiang &tmp)
{
if (tmp.num == tmp.m_map.size())
{
os << "No duplicates." << endl;
}
else
{
map<string, int>::iterator itor = tmp.m_map.begin();
for (; itor != tmp.m_map.end(); itor++)
{
if (1 == itor->second)
{
continue;
}
else
{
os << itor->first << " " << itor->second << endl;
}
}
}
return os;
}
int main()
{
string str;
char tmp[100];
int num;
LiQiang res;
scanf("%d", &num);
for (int i = 0; i < num; i++)
{
scanf("%s", tmp);
str = tmp;
res.add(str);
}
cout << res;
system("PAUSE");
return 0;
}
0 0
- PKU ACM 1002 487-3279 C++实现
- PKU ACM 1002 487-3279
- pku acm 1002
- Pku ACM 1002
- 487-3279 - PKU 1002
- 487-3279 - PKU 1002
- PKU 1002 487-3279
- pku 1002 487-3279
- Pku acm 1002 487-3279 排序算法解题报告(一) ----二叉查找数(BST)
- POJ 1002求487-3279解题报告——【PKU ACM】
- acm pku 1068 Parencodings的实现
- acm pku 1132 Border的具体实现
- pku-acm
- ACM-PKU
- pku oj 1002 487-3279
- acm pku 1056 IMMEDIATE DECODABILITY的代码实现
- acm pku 1107 W's Cipher的具体实现方法
- acm pku 1118 Lining Up的具体实现方法
- C++文件读写总结
- ZipInputStream类
- 淘寶的起源故事、技術發展之路
- openCV中的视频处理。。。
- 开源软件中的TOP10
- PKU ACM 1002 487-3279 C++实现
- 【OpenCV】访问Mat图像中每个像素的值
- NAND Flash闪存坏块的相关知识
- 计算机网络
- 30个数据可视化的简单图表工具
- springMVC整合mybatis时候配置mybatis-config异常
- 浅谈前端集成解决方案
- 定制打包自己的ISO镜像(kickstart)
- java常用设计模式