problem 1159
来源:互联网 发布:日本动漫推荐 知乎 编辑:程序博客网 时间:2024/05/17 01:36
Accepted 1159 C++ 00:03.33 3280K
STL写的,效率超低,不过代码很简单。
#include <stdio.h>
#include <string.h>
#include <map>
using namespace std;
const int aph[26] = {2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, -1, 7, 7, 8, 8, 8, 9, 9, 9, -1};
void solve(int n)
{
int cnt = 0, flag = 0;
map<int, int> table;
for(int i = 0; i < n; i++)
{
int temp = 0;
char c;
while(scanf("%c", &c) != EOF && c != ' ')
if(c != '-')
temp = (10 * temp + ((c >= 'A' && c <= 'Z') ? aph[c - 'A'] : (c - '0')));
table[temp]++;
}
for(map<int, int>::iterator it = table.begin(); it != table.end(); it++)
{
int temp = it->second;
if(temp > 1)
{
int p1 = (it->first) / 10000, p2 = (it->first) % 10000;
if(p1 < 10) printf("00");
else if(p1 < 100) printf("0");
printf("%d-", p1);
if(p2 < 10) printf("000");
else if(p2 < 100) printf("00");
else if(p2 < 1000) printf("0");
printf("%d %d/n", p2, temp);
flag = 1;//其实很不想用flag的,不爽.
}
}
if(flag == 0)
printf("No duplicates./n");
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("1159.txt", "r", stdin);
#endif
int t, n;
while(scanf("%d", &t) != EOF)
for(int i = 0; i < t; i++)
{
if(i > 0) printf("/n");
scanf("%d/n", &n);
solve(n);
}
#ifndef ONLINE_JUDGE
fclose(stdin);
#endif
return 0;
}
#include <string.h>
#include <map>
using namespace std;
const int aph[26] = {2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, -1, 7, 7, 8, 8, 8, 9, 9, 9, -1};
void solve(int n)
{
int cnt = 0, flag = 0;
map<int, int> table;
for(int i = 0; i < n; i++)
{
int temp = 0;
char c;
while(scanf("%c", &c) != EOF && c != ' ')
if(c != '-')
temp = (10 * temp + ((c >= 'A' && c <= 'Z') ? aph[c - 'A'] : (c - '0')));
table[temp]++;
}
for(map<int, int>::iterator it = table.begin(); it != table.end(); it++)
{
int temp = it->second;
if(temp > 1)
{
int p1 = (it->first) / 10000, p2 = (it->first) % 10000;
if(p1 < 10) printf("00");
else if(p1 < 100) printf("0");
printf("%d-", p1);
if(p2 < 10) printf("000");
else if(p2 < 100) printf("00");
else if(p2 < 1000) printf("0");
printf("%d %d/n", p2, temp);
flag = 1;//其实很不想用flag的,不爽.
}
}
if(flag == 0)
printf("No duplicates./n");
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("1159.txt", "r", stdin);
#endif
int t, n;
while(scanf("%d", &t) != EOF)
for(int i = 0; i < t; i++)
{
if(i > 0) printf("/n");
scanf("%d/n", &n);
solve(n);
}
#ifndef ONLINE_JUDGE
fclose(stdin);
#endif
return 0;
}
- problem 1159
- problem
- Problem
- problem
- Problem
- Problem
- Problem
- Problem
- Problem
- Problem
- problem
- Problem
- Problem
- Problem
- Problem
- Problem
- Problem
- Problem
- 产生不重复的随机数
- java nio client sample
- 2008年4月国家计算机等级考试二级C语言笔试参考答案
- 使用TortiseSVN&amp;Subversion笔记(三)
- java的JDBC连接mysql数据库时对于Datetime类型出现Cannot convert value '0000-00-00 00:00:00' from column 9 to TIMESTAMP.
- problem 1159
- CWnd::OnEraseBkgnd
- 如何 着手 学习c的嵌入式编程??c的基础很不错
- MIDP高级图形用户界面详解
- 关于retutn
- 成熟男人必看的5个故事
- 敏捷开发1-单一职责原则
- 被感冒困扰 4.10
- ajax中URL中传递“#”丢失的解决办法