URAL 1563. Bayan (STL map)
2015-06-01 13:09
260 查看
1563. Bayan
Time limit: 1.0 secondMemory limit: 64 MB
As everybody knows, there are a lot of stores in skyscrapers, it's the favourite place of glamorous girls. Blonde Cindy loves only one thing — the shopping. Today is one of the best days, she's going shopping to the new skyscraper
“Prisma”. At first she decided to visit all the stores. But actually the “Prisma” is so large that you can find not just one store of each brand. Every time when Cindy found the brand, she has visited before, she told “Bayan”, and went on shopping.
Cindy saw all the stores in the “Prisma”. So how many times did she tell “Bayan”?
Input
First line contains single integer N representing the number of stores in the “Prisma” (1 ≤ N ≤ 1000). In each of nextN lines the brand of store is written. The brands are the strings of Latin lettersand blanks. The length of the string is from 1 to 30. There are no brands, that differ only in register.
Output
Print the number of stores, Cindy didn't visit.Sample
input | output |
---|---|
12 ESPRIT Nice Connection Camelot Adilisik Lady and Gentleman City MEXX Camelot Sultanna Frantsuzova Camaieu MEXX Axara Camelot | 3 |
Problem Source: The XIIth USU Programing Championship, October 6, 2007
解析:当一个字符串在之前已经出现过时,说一次“Bayan”。用getline()或者gets()都可以读,要注意空格和换行。
PS:之前一直wrong,原来是题意理解错了。。。
AC代码:
#include <cstdio> #include <map> #include <string> #include <iostream> using namespace std; map<string, int> m; int main(){ #ifdef sxk freopen("in.txt", "r", stdin); #endif //sxk int n; string s; while(scanf("%d", &n)==1){ getchar(); int ans = 0; m.clear(); for(int i=0; i<n; i++){ getline(cin, s); if(m.count(s)) ans ++; //出现过 m[s] ++; } printf("%d\n", ans); } return 0; }
相关文章推荐
- 019_01播放视频之SurfaceView
- 30天,APP创业从0到1【重庆、青岛、成都】
- UCB CS162: Get sarted, create a docker container for UCB CS162 online course
- IsProcessInJob undeclared identifier
- Kafka flume 整合
- 在T-SQL语句中访问远程数据库(openrowset/opendatasource/openquery)
- Leetcode Problem.172—Factorial Trailing Zeroes
- 对List中的HashMap进行排序。
- 21分钟 MySQL 入门教程
- 关于android的ActionBarActivity过期的问题
- springmvc 表单字段list提交问题
- MD5加密不一致
- 腾讯网UED体验设计之旅
- android 屏幕适配
- Linux引导流程解析(1)
- Java:内存相关认识
- PC2日记——坑爹的第一天2014/08/28
- 可将canvas图像导出为多种格式图片的jQuery插件
- 16进制颜色代码大全
- CentOS安装Apache