CodeForces 589A -- A. Email Aliases (字符串水题 STL)
来源:互联网 发布:python ftp 下载文件 编辑:程序博客网 时间:2024/06/16 15:06
大体题意:
告诉你n 个邮箱名称,求出不同邮箱种类的个数,并输出不同种类邮箱。
思路:
根据题意:
首先把输入的邮箱名字全部转换为小写。
邮箱是bmail.com的比较特别,他是根据第一个加号之前进行判别,并忽略点(dot),来进行分类!
其余的邮箱则是全部来作为依据!
直接建立一个map<string,int> 来判别有没有存在就好了,然后给种类一个id 放到vector 即可!
详细见代码:
#include<bits/stdc++.h>using namespace std;const int maxn = 20000 + 10;const int inf = 0x3f3f3f3f;const double eps = 1e-8;const double pi = acos(-1.0);map<string,int>mp;int id = 0;int a[maxn];int vis[maxn];char s[maxn][108];char s2[maxn][108];char code[107];vector<string>v[maxn];int main(){ int n; scanf("%d",&n); for (int i = 0; i < n; ++i){ scanf("%s",s2[i]); strcpy(s[i],s2[i]); for (int j = 0; s[i][j] != 0; ++j)s[i][j] = tolower(s[i][j]); } for (int i = 0; i < n; ++i){ int pat = 0; for (;s[i][pat]!='@';++pat); strcpy(code,s[i]); if (strcmp(s[i]+pat+1,"bmail.com") == 0){ int dot = -1; for (int j = 0; j < pat; ++j){ if (s[i][j] == '+'){ dot = j; break; } } int cnt = 0; for (int j = 0; j < (dot == -1 ? pat : dot); ++j){ if (s[i][j] == '.')continue; code[cnt++] = s[i][j]; } code[cnt] = 0; } if (!mp.count(code)){ mp[code] = id; v[id].push_back(s2[i]); id++; } else{ v[mp[code]].push_back(s2[i]); } } printf("%d\n",id); for (int i = 0; i < id; ++i){ int len = v[i].size(); printf("%d",len); for (int j = 0; j < len ; ++j)printf(" %s",v[i][j].c_str()); puts(""); } return 0;}
0 0
- CodeForces 589A -- A. Email Aliases (字符串水题 STL)
- CodeForces 589A Email Aliases
- CodeForces 589A Email Aliases
- K - Email Aliases CodeForces - 589A
- 2016 Personal Training #7 Div.2 CodeForces 589A Email Aliases
- 【2015-2016 ACM-ICPC, NEERC, Southern Subregional Contest A】【模拟 STL-map】Email Aliases 不同邮箱的数量
- CodeForces - 589A(字符串)
- 2015-2016 ACM-ICPC, NEERC, Southern Subregional Contest A Email Aliases
- CodeForces 589A(处理字符串)
- codeforces 96A (字符串模拟水题)
- codeforces 133A HQ9+(字符串水题)
- codeforces 208A (STL做法)
- <a> Email
- codeforces 118A String Task(字符串水题)
- codeforces 236A . Boy or Girl(字符串水题)
- Codeforces 2A. Winner(字符串:模拟)
- CodeForces 705A Hulk(字符串输出)
- Codeforces 2A Winner (STL map使用)
- 运用JS设置cookie、读取cookie、删除cookie
- 关于D3JS图表库的学习
- Java多线程五:生产者和消费者模型(单个对单个)
- 使用UIPageViewController进行多页面管理 -
- Linux shell脚本攻略-学习笔记(7-9章)
- CodeForces 589A -- A. Email Aliases (字符串水题 STL)
- 把mysql和apache 加入到windows 服务中
- C语言与C++中static,extern的用法及区别总结
- 利用RecycleView实现类似ListView的Item点击,长按等操作事件以及点击后每一项在添加一个列表
- let变量
- ListView缓存原理剖析
- leetcode-371. Sum of Two Integers
- 使用第三方工具把对象转成json串
- 如何最高效地掌握所学的知识呢?