UVA 755 - 487--3279
来源:互联网 发布:刘慧芳 知乎 编辑:程序博客网 时间:2024/05/16 17:50
给出一些字符串,每个字符串对应一个电话号码,要求输出所有字符串中所包含的每种电话号码的个数(只输出出现次数大于1的),如果直接搜索的话会TLE,因为总共电话号码为100000,可以先把所有的字符串按题目要求转化成数字,然后用一个数组hash[10000000]存下所有的电话号码,如果输入的字符串转化为数字为a,则hash[a]++;
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<iostream>
using namespace std;
char tel[100001][100];
int hash[10000000];
int main()
{
int n;
cin>>n;
while(n--)
{
memset(hash,0,sizeof(hash));
int num,te=0;;
cin>>num;
char c;
cin.get(c);
int temp[100];
for(int i=0; i<num; i++)
{
cin.getline(tel[i],100,\'\\n\');
int len=strlen(tel[i]);
int k=0;
for(int j=0; j<len; j++)
{
if(tel[i][j]>=\'A\'&&tel[i][j]<=\'C\')
temp[k++]=2;
else if(tel[i][j]>=\'D\'&&tel[i][j]<=\'F\')
temp[k++]=3;
else if(tel[i][j]>=\'G\'&&tel[i][j]<=\'I\')
temp[k++]=4;
else if(tel[i][j]>=\'J\'&&tel[i][j]<=\'L\')
temp[k++]=5;
else if(tel[i][j]>=\'M\'&&tel[i][j]<=\'O\')
temp[k++]=6;
else if(tel[i][j]>=\'P\'&&tel[i][j]<=\'S\')
temp[k++]=7;
else if(tel[i][j]>=\'T\'&&tel[i][j]<=\'V\')
temp[k++]=8;
else if(tel[i][j]>=\'W\'&&tel[i][j]<=\'Y\')
temp[k++]=9;
else if(tel[i][j]>=\'0\'&&tel[i][j]<=\'9\')
temp[k++]=tel[i][j]-\'0\';
}
int sum=0;
int ss=1000000;
for(int j=0; j<7; j++)
{
sum+=temp[j]*ss;
ss/=10;
}
hash[sum]++;
}
int flag=0;
for(int i=0; i<10000000; i++)
{
if(hash[i]>1)
{
int a1=i/10000;
int a2=i%10000;
printf(\"%03d-%04d %d\\n\",a1,a2,hash[i]);
flag=1;
}
}
if(!flag)
{
cout<<\"No duplicates.\"<<endl;
}
if(n)
cout<<endl;
}
return 0;
}
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<iostream>
using namespace std;
char tel[100001][100];
int hash[10000000];
int main()
{
int n;
cin>>n;
while(n--)
{
memset(hash,0,sizeof(hash));
int num,te=0;;
cin>>num;
char c;
cin.get(c);
int temp[100];
for(int i=0; i<num; i++)
{
cin.getline(tel[i],100,\'\\n\');
int len=strlen(tel[i]);
int k=0;
for(int j=0; j<len; j++)
{
if(tel[i][j]>=\'A\'&&tel[i][j]<=\'C\')
temp[k++]=2;
else if(tel[i][j]>=\'D\'&&tel[i][j]<=\'F\')
temp[k++]=3;
else if(tel[i][j]>=\'G\'&&tel[i][j]<=\'I\')
temp[k++]=4;
else if(tel[i][j]>=\'J\'&&tel[i][j]<=\'L\')
temp[k++]=5;
else if(tel[i][j]>=\'M\'&&tel[i][j]<=\'O\')
temp[k++]=6;
else if(tel[i][j]>=\'P\'&&tel[i][j]<=\'S\')
temp[k++]=7;
else if(tel[i][j]>=\'T\'&&tel[i][j]<=\'V\')
temp[k++]=8;
else if(tel[i][j]>=\'W\'&&tel[i][j]<=\'Y\')
temp[k++]=9;
else if(tel[i][j]>=\'0\'&&tel[i][j]<=\'9\')
temp[k++]=tel[i][j]-\'0\';
}
int sum=0;
int ss=1000000;
for(int j=0; j<7; j++)
{
sum+=temp[j]*ss;
ss/=10;
}
hash[sum]++;
}
int flag=0;
for(int i=0; i<10000000; i++)
{
if(hash[i]>1)
{
int a1=i/10000;
int a2=i%10000;
printf(\"%03d-%04d %d\\n\",a1,a2,hash[i]);
flag=1;
}
}
if(!flag)
{
cout<<\"No duplicates.\"<<endl;
}
if(n)
cout<<endl;
}
return 0;
}
- UVa 755 - 487--3279
- uva 755 487--3279
- UVa 755 - 487--3279
- uva 755 - 487--3279
- UVA 755 487-3279
- UVA 755 - 487--3279
- UVa 755 - 487--3279
- UVa: 755 - 487--3279
- Uva-755-487--3279
- UVA 755 - 487--3279
- UVa 755 487-3279
- UVa 755 487-3279
- UVa 755 - 487--3279
- UVa:755 - 487--3279
- UVa 755 - 487--3279
- Uva 755 487--3279
- UVA - 755 487--3279
- UVA 755 - 487--3279
- HDU 2909 - Expected Allowance
- 123 - Searching Quickly
- UVA 107 - The Cat in the Hat
- HDU 1969 - Pie
- HDU 3233 - Download Manager
- UVA 755 - 487--3279
- UVA 10785 - The Mad Numerologist
- 10014 - Simple calculations
- 10719 - Quotient Polynomial
- UVA 550 - Multiplying by Rotation
- UVA 375 - Inscribed Circles and Isosceles Triangles
- UVA 10387 - Billiard
- UVA 11234 - Expressions
- UVA 106 - Fermat vs. Pythagoras