HDOJ 5007 Post Robot--2014网络赛西安赛区A题

题目来源:http://acm.hdu.edu.cn/showproblem.php?pid=5007

Post Robot

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)

Total Submission(s): 193    Accepted Submission(s): 164

Problem Description

DT is a big fan of digital products. He writes posts about technological products almost everyday in his blog.

But there is such few comments of his posts that he feels depressed all the day. As his best friend and an excellent programmer, DT asked you to help make his blog look more popular. He is so warm that you have no idea how to refuse. But you are unwilling to
read all of his boring posts word by word. So you decided to write a script to comment below his posts automatically.

After observation, you found words “Apple” appear everywhere in his posts. After your counting, you concluded that “Apple”, “iPhone”, “iPod”, “iPad” are the most high-frequency words in his blog. Once one of these words were read by your smart script, it will
make a comment “MAI MAI MAI!”, and go on reading the post.

In order to make it more funny, you, as a fan of Sony, also want to make some comments about Sony. So you want to add a new rule to the script: make a comment “SONY DAFA IS GOOD!” when “Sony” appears.

Input

A blog article described above, which contains only printable characters(whose ASCII code is between 32 and 127), CR(ASCII code 13, ‘\r’ in C/C++), LF(ASCII code 10, ‘\n’ in C/C++), please process input until EOF. Note all characters are case sensitive.

The size of the article does not exceed 8KB.

Output

Output should contains comments generated by your script, one per line.

Sample Input

Apple bananaiPad lemon ApplepiSony
233
Tim cook is doubi from Apple
iPhoneipad
iPhone30 is so biiiiiiig Microsoft
makes good App.

Sample Output

MAI MAI MAI!
MAI MAI MAI!
MAI MAI MAI!
SONY DAFA IS GOOD!
MAI MAI MAI!
MAI MAI MAI!
MAI MAI MAI!

Source

2014 ACM/ICPC Asia Regional Xi‘an Online

题意: 买买买~~ 索尼大法好!  输入一段字符串,每当出现“Apple”, “iPhone”, “iPod”, “iPad”  中的一个词则输出一句 MAI MAI MAI!  每出现一个Sony 则输出一句 SONY DAFA IS GOOD!

题解:简单字符串处理题~~ 拼的是速度&&细心   我的代码不大简洁的样子,待会看看其他人的如何。

AC代码:

#include<iostream>
#include<string>
#include<algorithm>
#define Max 10000
using namespace std;
string str,map[]={"Apple","iPhone","iPod","iPad"};
string out[]={"MAI MAI MAI!","SONY DAFA IS GOOD!"};
int outa[Max],outb[Max];
int main(){
	while(cin>>str){
		int len=str.size(),posa=0,posb=0,temp;
		for(int k=0;k<4;k++)
		for(int i=0;i<len;i++){
		if((temp=str.find(map[k],i))!=string::npos){
				outa[posa++]=temp;i=temp+1;
		}
		}
		for(int i=0;i<len;i++){
			if((temp=str.find("Sony",i))!=string::npos){
				outb[posb++]=temp;i=temp+1;
			}
		}
	int i=0,j=0;
	sort(outa,outa+posa);
	sort(outb,outb+posb);
	while(i+j<posa+posb){
		if(i==posa) {
			cout<<out[1]<<endl; j++;
		}
		else if(j==posb){
			cout<<out[0]<<endl; i++;
		}
		else if(outa[i]<outb[j]){
			cout<<out[0]<<endl;i++;
		}
		else {
			cout<<out[1]<<endl;j++;
		}
	}
}
	return 0;
}
时间: 2024-10-06 07:19:33

HDOJ 5007 Post Robot--2014网络赛西安赛区A题的相关文章

HDOJ 5012 Dice--2014网络赛西安赛区F题

题目来源:http://acm.hdu.edu.cn/showproblem.php?pid=5012 Dice Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 307    Accepted Submission(s): 183 Problem Description There are 2 special dices on the

[hdu5136]Yue Fei&#39;s Battle 2014 亚洲区域赛广州赛区J题(dp)

转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud 现场赛的时候由于有个地方有点小问题,没有成功AC,导致与金牌失之交臂. 由于今天下午有点事情,无法打重现,所以下午只是花了十分钟做了一道J题,抢了个FB,2333333333 Yue Fei's Battle Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 512000/512000 K (Java/Others)T

08年acm区域赛北京赛区 部分题解题报告

08年区域赛北京赛区 http://poj.org/searchproblem?field=source&key=Beijing+2008 POJ 3921 Destroying the bus stations 题目还是比较难的,当时的榜似乎只有4/25的通过/提交,其实题目数据很水.学长转换模型写了网络流求最小割,可以AC,不过自己造了个数据推翻了正确性.我写了个很挫的bfs套bfs,外层是最小的删除点数,内层是求最短路,数据很水可以AC.但比较蛋疼的在于bfs耗内存,而且队列中的点数是阶乘

2014 39th ACM-ICPC 西安赛区 总结

西安,打铁. 出发前听说是大赛区,签到的时候看了秩序册的队伍情况,264支队伍. 在听说是大赛区之前,我觉得我们队应该是银首,运气好+发挥超常的话或许有金,即保银冲金. 听到大赛区之后,觉得可能金区有难度,毕竟金的数量不根据队伍总数改变.当时觉得应该是银,运气差+发挥失常就是铜首. 万万没想到,打铁. 同行的另外还有三支队伍.大二的两支队伍,一支银一支铜.好像我们学院好久没有打铁了 热身赛,纸质很差,纸张黄黄的,字体模糊的,还很薄.共4题. 先是2题水题CD,我跟JM迅速水完后,WJ说B是冒泡的

HDOJ 5007 Post Robot

索尼大法好 Post Robot Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 156    Accepted Submission(s): 134 Problem Description DT is a big fan of digital products. He writes posts about technological

hdu 5038 (2014北京网络赛G 排序水题)

题意:有n个数字,带入10000 - (100 - ai) ^ 2公式得到n个数,输出n个数中频率最大的数,如果有并列就按值从小到大都输出输出,如果频率相同的数字是全部的n个数,就输出Bad....题解:统计数字个数和频率,排序后输出. Sample Input36100 100 100 99 98 1016100 100 100 99 99 1016100 100 98 99 99 97 Sample OutputCase #1:10000Case #2:Bad MushroomCase #3

urumqi 网络赛 C Coconut 水题

题目链接: 放不出来 题目描述: 每个站点有a[i] 个 椰子, 相邻站点的距离给出, 每天需要b个椰子, 问是否能够坚持到终点. 解题思路: 水一波儿 代码: #include <iostream> #include <cstdio> #include <string> #include <vector> #include <cstring> #include <iterator> #include <cmath> #i

2014西安赛区C题

将A[i]同他后面比他小的建边,然后求最大密度子图 #include <iostream> #include <algorithm> #include <string.h> #include <cstdio> #include <vector> #include <queue> #include <cmath> using namespace std; const int maxn=105; const double ep

网络赛牡丹江赛区E ZOJ3813(线段树)

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5345 给定序列P,定义序列S为P反复重复得到的一个无穷长的序列: if P = 3423537, then S = 3423537342353734235373423537... 再定义G(l, r) = Sl - Sl+1 + Sl+2 - ... + (-1)r-lSr 给两种操作: 1 x d:将序列P的第x想改为d(d是一个简单数字0~9) 2 l r  :求sum