题目链接

思路

开个一千万的数组计数,最后遍历即可。

#include<stdio.h>
#include<string.h>
#include<algorithm> using namespace std;
int num=0;
int mymap[10000000] = {0}; int change(char a[201])
{
int j=0, result=0;
for(int i=0;i<strlen(a);i++)
{
if(a[i] == '-') continue;
if(a[i] <= '9' && a[i] >= '0')
{
result = result*10+a[i]-'0';
continue;
}
if( a[i] <= 'O' && a[i] >= 'A' )
{
result = result*10+ (int)((a[i]-'A')/3) + 2;
continue;
}
switch (a[i])
{
case 'P':
case 'R':
case 'S':
result = result*10+7;
break;
case 'T':
case 'U':
case 'V':
result = result*10+8;
break;
case 'W':
case 'X':
case 'Y':
result = result*10+9;
break;
}
}
return result;
}
int main()
{
int n,times=0;
char temp[201];
scanf("%d",&n);
for(int i=0;i<n;i++)
{
scanf("%s",temp);
int flag = 0, t;
t = change(temp);
mymap[t] ++;
} int flag = 0;
for(int i=0;i<10000000;i++)
{
if(mymap[i] < 2) continue;
flag = 1;
char p[8] = {0};
sprintf(p,"%d",i);
if( strlen(p) <= 4 )
{
for(int j=0;j<3;j++)
printf("0");
printf("-");
for(int j=0;j<4-strlen(p);j++)
printf("0");
for(int j=0;j<strlen(p);j++)
printf("%c",p[j]);
}
else
{
for(int j=0;j<7-strlen(p);j++)
printf("0");
for(int j=0;j<strlen(p)-4;j++)
printf("%c",p[j]);
printf("-");
for(int j=strlen(p)-4;j<strlen(p);j++)
printf("%c",p[j]);
}
printf(" %d\n",mymap[i]);
}
if( flag == 0 ) puts("No duplicates.");
return 0;
}

百炼OJ - 1002 - 方便记忆的电话号码的更多相关文章

  1. PKU OJ 1002 487-3279

    PKU OJ 1002 487-3279 487-3279 Description Businesses like to have memorable telephone numbers. One w ...

  2. 九度OJ 1002:Grading

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:18410 解决:4753 题目描述: Grading hundreds of thousands of Graduate Entrance ...

  3. Light oj 1002 Country Roads (Dijkstra)

    题目连接: http://www.lightoj.com/volume_showproblem.php?problem=1002 题目描述: 有n个城市,从0到n-1开始编号,n个城市之间有m条边,中 ...

  4. OJ#1002 又是a+b

    题目描述: 给定两个正整数a.b(0 < a,b < =10000),求出a+b的和 输入描述: 多组输入,每组输入为一行,里面有2个数a,b(0 < a,b < =10000 ...

  5. oj 1002题 (大数题)

    #include <stdio.h> #include <string.h> int main(void) { int q,j,h,k,l; int d; ],s2[];//题 ...

  6. 九度oj 1002 Grading 2011年浙江大学计算机及软件工程研究生机试真题

    #include<iostream> #include<queue> #include<cstdio> #include<cstring> #inclu ...

  7. 杭电oj 1002

    #include <iostream> #include <algorithm> using namespace std; int nCases; ], n[]; ], b[] ...

  8. PKU 百炼OJ 简单密码

    http://bailian.openjudge.cn/practice/2767/ #include<iostream> #include <cmath> #include ...

  9. PKU 百炼OJ 奖学金

    http://bailian.openjudge.cn/ss2017/A/ #include<iostream> #include <cmath> #include <m ...

随机推荐

  1. php 获取视频时长

    利用ffmpeg只能获取到本地视频的信息. function video_time($file) { ob_start(); passthru(sprintf(FFMPEG_PATH, $file)) ...

  2. python里的复数complex

    复数是一个数学概念,包含了实部和虚部.在python设计语言中,可以直接定义以j为单位,也可以使用complex函数创建复数,这个函数可以传实部和虚部,也可以只传实部. 我们把形如z=a+bj(a,b ...

  3. python django项目的搭建及初始配置

    1.创建项目并创建应用 django-admin startproject my_project # 创建项目python manage.py startapp my_app # 创建应用 1.1 项 ...

  4. string类型的应用场景 —— Redis实战经验

    string类型是实战中应用最多的数据类型,Redis的一些特性决定了string类型的应用场景. 1. Redis的数据是共享的 如果将用户信息存储在web服务的本地缓存,则每个web服务都会缓存一 ...

  5. 【Unity|C#】基础篇(15)——异常处理(try/catch/throw)

    [学习资料] <C#图解教程>(第22章):https://www.cnblogs.com/moonache/p/7687551.html 电子书下载:https://pan.baidu. ...

  6. TODO:rest和restful接口是什么?

    todo: 参考: http://www.ruanyifeng.com/blog/2018/10/restful-api-best-practices.html https://www.jianshu ...

  7. 4.Docker 操作容器

    启动容器 所需要的命令主要为 docker run.例如,下面的命令输出一个 “Hello World”,之后终止容器. docker run ubuntu:16.04 /bin/echo 'Hell ...

  8. javaScript入门(函数)

    目录 JavaScript函数 函数是什么 函数返回值 return特点: 递归函数 匿名函数(anoymous) 自执行函数(通过匿名函数实现) 回调函数 闭包函数 构造函数 构造函数两大类 注意事 ...

  9. LightOJ-1370 Bi-shoe and Phi-shoe (欧拉函数+二分)

    Problem Description Bamboo Pole-vault is a massively popular sport in Xzhiland. And Master Phi-shoe ...

  10. Python爬虫连载8-JS加密(一)

    一.JS加密 1.有的反爬虫策略采用js对需要传输的数据进行加密处理. 2.经过加密,传输的就是密文 3.加密函数或者过程一定是在浏览器完成,也就是一定会把代码(js代码)暴露给使用者 4.通多阅读加 ...