传送门

[http://codeforces.com/contest/898/problem/C]

题意

题意比较难理解直接看样例就知道了,给你个n接下来n行,每行包括一个名字和号码的数量,还有具体的每个号码

让你整理他的电话本,使得一个人的号码不能有重复,而且一个号码不能是另一个号码的后缀

分析

首先可以对一个人的所有号码去重,用map<string,set<string>> m来存信息可以,set具有惟一性,然后输出m.size()即为所有联系人
然后用三重循环来处理使得一个人的号码不能有重复,而且一个号码不能是另一个号码的后缀,关键是判断一个字符串是否是另一个字符串的
后缀,substr()函数
1. 用途:一种构造string的方法 2. 形式:s.substr(pos, n) 3. 解释:返回一个string,包含s中从pos开始的n个字符的拷贝(pos的默认值是0,n的默认值是s.size() - pos,即不加参数会默认拷贝整个s) 4. 补充:若pos的值超过了string的大小,则substr函数会抛出一个out_of_range异常;若pos+n的值超过了string的大小,则substr会调整n的值,只拷贝到string的末尾

例如:

#include<string>
#include<iostream>
using namespace std;
int main()
{
  string s("12345asdf");
  string a = s.substr(0,5); //获得字符串s中从第0位开始的长度为5的字符串
  cout << a << endl;
}
输出结果为:12345

本题代码

#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
//freopen("in.txt","r",stdin);
while(cin>>n){
map<string,set<string> > m;
int num;
string name;
for(int i=0;i<n;i++){
cin>>name>>num;
string s;
for(int j=0;j<num;j++){
cin>>s;
m[name].insert(s);
}
}
cout<<m.size()<<endl;
for(map<string,set<string> >::iterator it=m.begin();it!=m.end();it++){
string name=(*it).first;
vector<string> v;
for(set<string>::iterator at=m[name].begin();at!=m[name].end();at++){
string a=*at;
bool flag=1;
for(set<string>::iterator bt=m[name].begin();bt!=m[name].end();bt++){
string b=*bt;
if(a==b||a.length()>b.length()) continue;
if(b.substr(b.length()-a.length(),a.length())==a)
{
flag=0; break;
}
}
if(flag) v.push_back(a);
}
cout<<name<<' '<<v.size()<<' ';
for(int i=0;i<v.size();i++)
cout<<v[i]<<' ';
cout<<endl;
}
}
return 0;
}

898 C. Phone Numbers的更多相关文章

  1. Java 位运算2-LeetCode 201 Bitwise AND of Numbers Range

    在Java位运算总结-leetcode题目博文中总结了Java提供的按位运算操作符,今天又碰到LeetCode中一道按位操作的题目 Given a range [m, n] where 0 <= ...

  2. POJ 2739. Sum of Consecutive Prime Numbers

    Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 20050 ...

  3. [LeetCode] Add Two Numbers II 两个数字相加之二

    You are given two linked lists representing two non-negative numbers. The most significant digit com ...

  4. [LeetCode] Maximum XOR of Two Numbers in an Array 数组中异或值最大的两个数字

    Given a non-empty array of numbers, a0, a1, a2, … , an-1, where 0 ≤ ai < 231. Find the maximum re ...

  5. [LeetCode] Count Numbers with Unique Digits 计算各位不相同的数字个数

    Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10n. Examp ...

  6. [LeetCode] Bitwise AND of Numbers Range 数字范围位相与

    Given a range [m, n] where 0 <= m <= n <= 2147483647, return the bitwise AND of all numbers ...

  7. [LeetCode] Valid Phone Numbers 验证电话号码

    Given a text file file.txt that contains list of phone numbers (one per line), write a one liner bas ...

  8. [LeetCode] Consecutive Numbers 连续的数字

    Write a SQL query to find all numbers that appear at least three times consecutively. +----+-----+ | ...

  9. [LeetCode] Compare Version Numbers 版本比较

    Compare two version numbers version1 and version1.If version1 > version2 return 1, if version1 &l ...

随机推荐

  1. 【PAT】B1061 判断题(15 分)

    简单逻辑题, #include<stdio.h> #include<algorithm> using namespace std; int main(){ int N,M;// ...

  2. MySQL基本操作命令

    数据库的基本操作命令 1.登录MySQL -- 进入数据库的方法一 mysql -uroot -pmysql # mysql 数据库密码(显示) -- 进入数据库的方法二 mysql -uroot - ...

  3. python 计时累积超过24小时时继续往上累加

    最近在做一个工具,要求在工具上面加上程序运行的时间,所以做了个计时器 在网上找了很多发现都是24小时制的,超过24小时后就会回0 然后自己根据24小时制修改了一个不停累加时间的 若是想超过24小时后以 ...

  4. February 4th, 2018 Week 6th Sunday

    Hope clouds observation. 心怀希望会蒙蔽双眼,影响判断. Almost every of us thinks we would be the master of our liv ...

  5. Beta冲刺博客集合贴

    Beta阶段第一次冲刺 Beta阶段第二次冲刺 Beta阶段第三次冲刺 Beta阶段第四次冲刺 Beta阶段第五次冲刺 Beta阶段总结博客

  6. java 代码说明制作讲解

    命令格式及介绍 javadoc -d 文档存放目录 -author -version 源文件名.java 这条命令编译一个名为"源文件名.java"的 java 源文件,并将生成的 ...

  7. 【CSS3】transition过渡和animation动画

    转自:http://blog.csdn.net/XIAOZHUXMEN/article/details/52003135 写在前面的话: 最近写css动画发现把tansition和animation弄 ...

  8. Spring Boot application starters

    https://docs.spring.io/spring-boot/docs/2.1.0.RELEASE/reference/htmlsingle/#using-boot-dependency-ma ...

  9. 转:// 再说 Oracle RAC services

    应用程序工作负载在Oracle 10g中可以被定为services,也称之为服务,能够在单实例中使用,也能够在RAC中单独使用和管理.因此整个数据库负载能够被分割为多个不同的services,通过管理 ...

  10. CGLIB 和 JDK生成动态代理类的区别(转)

    文章转自http://luyuanliang.iteye.com/blog/1137292 AOP 使用的设计模式就是代理模式,是对IOC设计的补充.为了扩展性,往往会加上反射,动态生成字节码,生成代 ...