HDOJ 5007 Post Robot -- question A, hdojrobot -- 2014, Xi'an division, 2014

Source: Internet
Author: User
Tags printable characters

HDOJ 5007 Post Robot -- question A, hdojrobot -- 2014, Xi'an division, 2014

Source: http://acm.hdu.edu.cn/showproblem.php? Pid = 1, 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 DescriptionDT is a big fan of digital products. He writes posts about original ical 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! ", 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.
 
InputA 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.
OutputOutput shocould contains comments generated by your script, one per line.
Sample Input
Apple bananaiPad lemon ApplepiSony233Tim cook is doubi from AppleiPhoneipadiPhone30 is so biiiiiiig Microsoftmakes 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!
 
Source2014 ACM/ICPC Asia Regional Xi 'an Online question: Buy ~~ Great Sony! Input a string. Whenever a word in "Apple", "iPhone", "iPod", or "iPad" appears, output a MAI! Every time a Sony appears, a sony dafa is good!
Question: simple string processing question ~~ It is a combination of speed and carefulness. My code is not very concise, so I will wait to see how others are doing.
AC code:
#include<iostream>#include<string>#include<algorithm>#define Max 10000using 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;}







Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.