POJ 1002 487-3279
来源:互联网 发布:php就业形势 编辑:程序博客网 时间:2024/05/24 13:28
【题意】给定字符串按照规定转为标准格式,问有多少个重复的标准格式,输出其格式及个数,若没有输出No duplicates.
【分析】
没啥好说的了,转成对应的就是了,注意不能用整型输出,不然输出032-0341会变成32-341。
装逼的话,可以用字典树做一下......
漏输出“No duplicates.” WA了一次......
【代码】
#include <cstdio>
#include <cstring>
#include <cstdlib>
using namespace std;
const int letter[26]={2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,0,7,7,8,8,8,9,9,9,0};
int n,len;
char s[50];
struct T
{
int next[10],size;
}tr[2000000];
int tot=1;
int d;
void ins(void)
{
int now=1;
tr[now].size++;
for (int i=1;i<=len;i++)
if ('0'<=s[i]&&s[i]<='9'||'A'<=s[i]&&s[i]<='Z'&&letter[s[i]-'A'])
{
int nxt=('0'<=s[i]&&s[i]<='9'?s[i]-'0':letter[s[i]-'A']);
if (!tr[now].next[nxt]) tr[now].next[nxt]=++tot;
tr[now=tr[now].next[nxt]].size++;
}
}
void DFS(int now,int dep)
{
if (dep==7)
{
if (tr[now].size>1) printf("%s %d\n",s,tr[now].size),d=1;
return;
}
if (dep==3) s[++len]='-';
for (int i=0;i<10;i++)
if (tr[tr[now].next[i]].size)
{
s[++len]=i+'0';
DFS(tr[now].next[i],dep+1);
s[len--]=0;
}
if (dep==3) s[len--]=0;
}
int main(void)
{
scanf("%d",&n);
for (int i=1;i<=n;i++)
{
scanf("%s",&s[1]);
len=strlen(&s[1]);
ins();
}
memset(s,0,sizeof s),len=-1;
DFS(1,0);
if (!d) printf("No duplicates.\n");
return 0;
}
- 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
- NOIP 2014 提高组 Day2 T2 寻找道路
- 四,从头到尾在myeclipse中的java开发环境搭建之SQLServer2000数据库的安装
- 杭电-2099 整除的尾数
- NOIP 2014 提高组 Day2 T1 无线网路发射器选址
- POJ 1001 Exponentiation
- POJ 1002 487-3279
- C#设计模式(十三)迭代器模式
- POJ 1003 Hangover
- 用 Tomcat 和 Eclipse 开发 Web 应用程序
- POJ 1004 Financial Management
- POJ 1005 I Think I Need a Houseboat
- Tomcat全攻略
- POJ 1006 Biorhythms
- POJ 1007 DNA Sorting