ACM_水题你要信了(修改版)
水题你要信了
Time Limit: 2000/1000ms (Java/Others)
Problem Description:
某发最近又认识了很多妹(han)子,可是妹(han)子一多不免有时会忘记那么一两个,为了记得他们的名字,发哥设计了一个记录器。对于每个他刚认识的妹(han)子,他都把妹子的名字放进记录器里,如果记录器已经有这个妹子的名字,则在这个妹子的名字后面加上一个数字(数字从1开始),输出妹子的名字加上数字。若记录器没有这个妹子的记录,则输出OH GOD。
Input:
(EOF)输入一个数字n表示发哥认识的妹子(1<=N<=10^5),接下来n行每行一个字符串,字符串不超过100个小写字母。
Output:
如描述。
Sample Input:
6
first
first
second
second
third
first
Sample Output:
OH GOD
first1
OH GOD
second1
OH GOD
first2
解题思路:map容器过,并且要用c语言的输入输出,不然老是超时=_=||。map查找时间为O(logn),总的时间复杂度是O(nlogn)。同样的题目(这题的字符串长度比原来扩大了1倍)链接:ACM_水题你信吗
AC代码:(225ms)
#include<bits/stdc++.h>
using namespace std;
int main(){
int t;string str;str.resize();//预先分配空间101
while(~scanf("%d",&t)){
getchar();map<string,int> mp;
while(t--){
scanf("%s",&str[]);//string类用scanf读取
if(mp.find(str)==mp.end()){printf("OH GOD\n");mp[str]++;}
else printf("%s%d\n",str.c_str(),mp[str]++);//string类用c语言格式输出
}
}
return ;
}
ACM_水题你要信了(修改版)的更多相关文章
- ACM_水题你信吗
水题你信吗 Time Limit: 2000/1000ms (Java/Others) Problem Description: 某发最近又认识了很多妹(han)子,可是妹(han)子一多不免有时会忘 ...
- [ACM_水题] UVA 12502 Three Families [2人干3人的活后分钱,水]
Three Families Three families share a garden. They usually clean the garden together at the end o ...
- [ACM_水题] Yet Another Story of Rock-paper-scissors [超水 剪刀石头布]
Description Akihisa and Hideyoshi were lovers. They were sentenced to death by the FFF Inquisition. ...
- [ACM_水题] UVA 11729 Commando War [不可同时交代任务 可同时执行 最短完成全部时间 贪心]
There is a war and it doesn't look very promising for your country. Now it's time to act. You have a ...
- [ACM_水题] UVA 11292 Dragon of Loowater [勇士斗恶龙 双数组排序 贪心]
Once upon a time, in the Kingdom of Loowater, a minor nuisance turned into a major problem. The shor ...
- [ACM_水题] ZOJ 3706 [Break Standard Weight 砝码拆分,可称质量种类,暴力]
The balance was the first mass measuring instrument invented. In its traditional form, it consists o ...
- [ACM_水题] ZOJ 3714 [Java Beans 环中连续m个数最大值]
There are N little kids sitting in a circle, each of them are carrying some java beans in their hand ...
- [ACM_水题] ZOJ 3712 [Hard to Play 300 100 50 最大最小]
MightyHorse is playing a music game called osu!. After playing for several months, MightyHorse disco ...
- [ACM_水题] 不要62(hdu oj 2089, 不含62和4的数字统计)
Problem Description 杭州人称那些傻乎乎粘嗒嗒的人为62(音:laoer).杭州交通管理局经常会扩充一些的士车牌照,新近出来一个好消息,以后上牌照,不再含有不吉利的数字了,这样一来, ...
随机推荐
- mysql根据用户的邀请码查询该用户所有的上级
SELECT T1.lvl AS 'level', T2.id AS 'id', T2.zid AS 'zid', T2.self_invite AS 'selfInvite', T2.invite_ ...
- Mysql学习总结(42)——MySql常用脚本大全
备份 (所有) C:\Program Files\MySQL\MySQL Server 5.6\bin>mysqldump --no-defaults -hlocalhost -P3306 -u ...
- 重载与重写的区别----https://blog.csdn.net/zhu_apollo/article/details/1852542
重载 overloading 1) 方法重载是让类以统一的方式处理不同类型数据的一种手段.多个同名函数同时存在,具有不同的参数个数/类型.重载是一个类中多态性的一种表现. ...
- 6、Java并发性和多线程-并发性与并行性
以下内容转自http://tutorials.jenkov.com/java-concurrency/concurrency-vs-parallelism.html(使用谷歌翻译): 术语并发和并行性 ...
- 数据结构——算法之(027)( 在O(1)时间内删除链表结点)
[申明:本文仅限于自我归纳总结和相互交流,有纰漏还望各位指出. 联系邮箱:Mr_chenping@163.com] 题目:在O(1)时间内删除链表结点.且不知道链表头 题目分析: 1.把要删除节点的下 ...
- about service in android
注意:标红处! A Service is an application component representing either an application's desire to perform ...
- [DB][MySql]关于取得自增字段的值、及@@IDENTITY 与并发性问题
对于刚从Oracle转向MySql的人都会为,MySql中没有Oracle里的Sequence而感到困惑.MySql中没有了Sequence,那么MySql的主键用什么方式来实现最好呢? 主要有下面几 ...
- HDU5441 Travel 离线并查集
Travel Problem Description Jack likes to travel around the world, but he doesn’t like to wait. Now, ...
- ios7--UIImageView
// // ViewController.m // 03-UIImageView的使用 // #import "ViewController.h" @interface ViewC ...
- tiny4412学习(四)之移植linux-设备树(1)设备树基础知识及GPIO中断【转】
本文转载自:http://blog.csdn.net/fengyuwuzu0519/article/details/74177978 版权声明:本文为博主原创文章,转载请注明http://blog.c ...