【冀宝要逆袭】UESTC-486-Good Morning
来源:互联网 发布:图书馆管理系统数据库 编辑:程序博客网 时间:2024/05/29 08:31
又是一道简单但是有点坑的题
问题描述
Sam loves Lily very much that he shows his love to her through all kinds of ways. This morning, Lily received an e-mail from Sam. Lily knows that Sam hided “good morning” in this mail. Lily tried several ways to resort the letters (including the space ’ ‘) so that more “good morning”s could be found. The number of “good morning” appeared in a specified string equals the number of positions from which Lily could see a consecutive string “good morning”.
With so many letters, Lily is about to be dizzy. She asks you to tell her what is the maximum number of “good morning”s appear in this mail after rearranged in some way.
输入
First an integer T (T≤20), indicates there are T test cases.
Every test case begins with a single line consist of only lowercase letters and space which is at most 1000 characters.
输出
For every test case, you should output Case #k: first, where k indicates the case number and starts at 1. Then output an integer indicating the answer to this test case.
样例输入
[“2\ngninrom doog\nggoooodd mmoorrnniinngg”]
样例输出
[“Case #1: 1\nCase #2: 2”]
#include <iostream>#include <string.h>#include <algorithm>using namespace std;int main(){ int t,i; int cas=0; string str; int num[10]; cin>>t; getline(cin,str); while(t--) { memset(num,0,sizeof(num)); getline(cin,str); for(i=0;i<str.size();i++) { if(str[i]=='g')num[0]++; else if(str[i]=='o')num[1]++; else if(str[i]=='d')num[2]++; else if(str[i]=='m')num[3]++; else if(str[i]=='n')num[4]++; else if(str[i]=='r')num[5]++; else if(str[i]=='i')num[6]++; else if(str[i]==' ')num[7]++; } num[0]--;num[1]/=3;num[4]/=2; int count=*min_element(num,num+7) ; cout<<"Case #"<<++cas<<": "<<count<<endl; } return 0;}
这道题呢,刚开始的想法很简单就是统计每个字符的数目,然后除它的权重,统计每个字符的最小值就是hide的good morning的个数,但是之后即发现了一个问题,因为good morning的首字母和末尾字母都是g 如果出现了good morningood morning 这个情况的话是包含两个早上好的,但是结果只会输出1,考虑到以上连接情况发现g的值只要减一,即可给出答案。
- 【冀宝要逆袭】UESTC-486-Good Morning
- Good Morning!
- Good morning
- Good Morning
- Good morning [字符串]
- 1279: Good morning
- Good morning [字符串]
- 1279: Good morning
- CFgym:Good morning!(dfs)
- Good Morning Beijing,Good Night Shanghai
- Good Numbers UESTC - 832
- UVALive 6934 Good morning! 打表判断
- Regionals 2014 >> Europe - Central >> 6934 - Good morning!
- 问题 A: Good morning 【字符串的处理】
- 奥运英语[1] 你好! Hello, Good morning, Good afternoon 和 Good evening
- 奥运英语[2] 你好! 早上好!Hi! Good Morning.
- morning
- morning
- 【OC05-2】NSSet、NSNumber、NSValue、NSDate、异常处理(连载七)
- 跟我一起写makefile--学习笔记1--makefile概况
- OC学习笔记三 (3 9.OC5-构造方法和description方法 变量方法作用域)
- 产生冠军
- 树的重心
- 【冀宝要逆袭】UESTC-486-Good Morning
- 折扣BUG
- 2013 蟠桃记
- 【微信分享】王团结:如何用Hadoop/Spark构建七牛数据平台
- hdoj2199Can you solve this equation?
- 多线程访问共享数据(2)
- 生成动态验证图片
- iOS -读取plist文件
- 南阳 oj D的小L 题目366