Codeforces Round #451 (Div. 2) C. Phone Numbers
来源:互联网 发布:福禄克网络官网 编辑:程序博客网 时间:2024/05/14 21:23
题目大意
问有多少不同的人以及每个人有多少种不同号码,一个串是另一个后缀则算相同号码。
题解
先将相同的人的电话合并,然后暴力去重就行了。
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;int read(){ char ch=getchar();int f=0; while(ch<'0'||ch>'9') ch=getchar(); while(ch>='0'&&ch<='9') {f=f*10+(ch^48);ch=getchar();} return f;}struct data{ string name; int size; string num[505]; int ans;}a[55],b[55];int n,tot;bool vis[105];bool cmp(string x,string y){ return x.length()>y.length();}bool check(string x,string y){ int l1=x.length(),l2=y.length(); for(int i=0;i<l2;i++) { if(y[i]!=x[l1-l2+i]) return 0; } return 1;}bool cmp2(data x,data y){ return x.name<y.name;}int main(){ n=read(); for(int i=1;i<=n;i++) { cin>>a[i].name; a[i].size=read(); for(int j=1;j<=a[i].size;j++) { cin>>a[i].num[j]; } } sort(a+1,a+n+1,cmp2); for(int i=1;i<=n;i++) { if(a[i].name==a[i-1].name) { for(int j=1;j<=a[i].size;j++) b[tot].num[++b[tot].size]=a[i].num[j]; } else { b[++tot].name=a[i].name; for(int j=1;j<=a[i].size;j++) b[tot].num[++b[tot].size]=a[i].num[j]; } } cout<<tot<<endl; for(int i=1;i<=tot;i++) { memset(vis,0,sizeof(vis)); sort(b[i].num+1,b[i].num+b[i].size+1,cmp); for(int j=1;j<=b[i].size;j++) { if(!vis[j]) { b[i].ans++; for(int k=j+1;k<=b[i].size;k++) { if(check(b[i].num[j],b[i].num[k])) { vis[k]=1; } } } } cout<<b[i].name<<" "<<b[i].ans<<" "; for(int j=1;j<=b[i].size;j++) { if(!vis[j]) cout<<b[i].num[j]<<" "; } cout<<endl; }}
阅读全文
0 0
- Codeforces Round #451 (Div. 2) C. Phone Numbers
- codeforces Round #451 (Div. 2) Phone Numbers
- Codeforces Round #226 (Div. 2) C. Bear and Prime Numbers
- Codeforces Round #226 (Div. 2)C. Bear and Prime Numbers
- Codeforces Round #240 (Div. 2) C. Mashmokh and Numbers
- Codeforces Round #181 (Div. 2)---C. Beautiful Numbers
- Codeforces Beta Round #34 (Div. 2) C. Page Numbers
- Codeforces Round #226 (Div. 2)--C. Bear and Prime Numbers
- Codeforces Round #451 (Div. 2) C
- Codeforces Round #451 (Div. 2) C
- Codeforces Round #FF (Div. 1) C - DZY Loves Fibonacci Numbers
- Codeforces Round #FF (Div. 1) C. DZY Loves Fibonacci Numbers
- codeforces 898C. Phone Numbers
- 【codeforces】Codeforces Round #370 (Div. 2) C
- Codeforces Round #209 (Div. 2)-C. Prime Number(set)和D. Pair of Numbers(线段树)
- Codeforces Beta Round #9 (Div.2 Only) C.Hexadecimal's Numbers 二进制思想、技巧题
- Codeforces Round #226 (Div. 2) C. Bear and Prime Numbers(素数筛法)
- Codeforces Round #226 (Div. 2) C. Bear and Prime Numbers(暴力)
- chmod命令详细用法
- 函数的多个参数va_list, va_start, va_avg, va_end的使用
- Intellij IDEA Mybatis plugin插件破解安装
- MySQL表中有外键约束时级联删除报错annot delete or update a parent row: a foreign key constraint fails
- Koltin数据类之解构申明
- Codeforces Round #451 (Div. 2) C. Phone Numbers
- 二叉树--uva699 二叉树递归遍历
- 环境变量PATH
- 使用Spring的Pageable来实现分页查询
- XML
- JVM的GC机制<一>新生代GC
- redis.conf 配置文件详解
- mysql百万级数据量根据索引优化查询速度
- ROM和RAM