POJ1002_487-3279_C++
题目:http://poj.org/problem?id=1002
我知道你们最需要的是这个 [ 手动滑稽 ]

STD 给出的方法是丢进一个数组,然后排序,相邻的是重复的
这个方法,时间复杂度很不错,也确实很好,但是最快的写法是
直接丢进对应的数组统计,然后 for 一遍数组看是否大于 1
注意没有满 7 位的时候要输出前导零
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std; char a[],s[],w[];
int b[];
int main()
{
int i,j,n,len,x;
bool flag=;
scanf("%d\n",&n);
a['A']=a['B']=a['C']='';
a['D']=a['E']=a['F']='';
a['G']=a['H']=a['I']='';
a['J']=a['K']=a['L']='';
a['M']=a['N']=a['O']='';
a['P']=a['R']=a['S']='';
a['T']=a['U']=a['V']='';
a['W']=a['X']=a['Y']='';
for (i=;i<=n;i++)
{
scanf("%s",s);
len=strlen(s);
x=;
for (j=;j<len;j++)
{
if (s[j]>='A'&&s[j]<='Z') s[j]=a[s[j]];
if (s[j]>=''&&s[j]<='') x=x*+s[j]-'';
}
b[x]++;
}
for (i=;i<;i++)
if (b[i]>)
{
for (x=i,j=;j<=;j++)
{
w[j]=x%+'';
x/=;
}
for (;j;j--) putchar(j>?w[j-]:j<?w[j]:'-');
printf(" %d\n",b[i]);
flag=;
}
if (flag) printf("No duplicates.\n");
return ;
}
见到的好博客,可以看出真的是用心写了
http://blog.csdn.net/thebestdavid/article/details/10986813
版权所有,转载请联系作者,违者必究
联系方式:http://www.cnblogs.com/hadilo/p/5932395.html
随机推荐
- 【jmeter】non-gui模式运行
operty文件,默认是使用JMETER_HOME/bin目录下的jmeter.properties,如果用户自定义有其它的配置,在这里加上 #用法如下: -p user.properties -q, ...
- SPOJ #2 Prime Generator
My first idea was Sieve of Eratosthenes, too. But obviously my coding was not optimal and it exceede ...
- asp.net mvc 页面传值的方法总结
转自:http://msprogrammer.serviciipeweb.ro/2012/01/15/usual-methods-to-transfer-data-from-page-to-page- ...
- 剑指offer系列37----数据流中的中位数
[题目]如何得到一个数据流中的中位数?如果从数据流中读出奇数个数值, * 那么中位数就是所有数值排序之后位于中间的数值. package com.exe8.offer; import java.uti ...
- Python 处理多层嵌套列表
>>> movies =[ "the holy grail", 1975,"terry jones",91, ["graham ch ...
- elasticsearch2
简单认为是可以在命令行下访问url的一个工具 curl是利用URL语法在命令行方式下工作的开源文件传输工具,使用curl可以简单实现常见的get/post请求. curl -x 指定http请求的方法 ...
- RAC_Oracle集群服务安装Grid Infrastructure(案例)
2015-01-24 Created By BaoXinjian Thanks and Regards
- PLSQL_性能优化系列06_Oracle Soft Parse / Hard Parse软硬解析
2014-08-11 Createed By BaoXinjian
- Codeforces Round #364 (Div. 2) Cells Not Under Attack
Cells Not Under Attack 题意: 给出n*n的地图,有给你m个坐标,是棋子,一个棋子可以把一行一列都攻击到,在根据下面的图,就可以看出让你求阴影(即没有被攻击)的方块个数 题解: ...
- Codeforces Round #358 (Div. 2)B. Alyona and Mex
B. Alyona and Mex time limit per test 1 second memory limit per test 256 megabytes input standard in ...