COJ 0036 数数happy有多少个?
2015-06-21 10:59
323 查看
数数happy有多少个? |
难度级别:B; 运行时间限制:1000ms; 运行空间限制:51200KB; 代码长度限制:2000000B |
试题描述 |
图图是个爱动脑子、观察能力很强的好学生。近期他正学英语单词,练字时无意识地写了一串小写英文字母,他发现这串字母中包含了很多个happy,他决定计算一下到底有多少个happy。规则是这样的:在该字符串提取任意位置的字符组成新的单词串,不改变其在原字符串中的相对顺序,请你编写程序帮助图图统计出新的单词串种最多有多少个happy。 |
输入 |
输入只有一行,含有一个字符串。字符串由小写字母a – z组成。此字符串长度不超过10000。 |
输出 |
一个非复整数。表示按照题目描述的规则最多能够组成单词happy的个数。 |
输入示例 |
hahappyppy |
输出示例 |
2 |
#include<iostream> #include<cstdio> #include<cmath> #include<algorithm> #include<queue> #include<cstring> #define PAU putchar(' ') #define ENT putchar('\n') using namespace std; inline int read(){ int x=0,sig=1;char ch=getchar(); while(!isdigit(ch)){if(ch=='-')sig=-1;ch=getchar();} while(isdigit(ch))x=10*x+ch-'0',ch=getchar(); return x*=sig; } inline void write(int x){ if(x==0){putchar('0');return;}if(x<0)putchar('-'),x=-x; int len=0,buf[15];while(x)buf[len++]=x%10,x/=10; for(int i=len-1;i>=0;i--)putchar(buf[i]+'0');return; } char ch;int cnt[4]; void init(){ for(ch=getchar();isalpha(ch);ch=getchar()){ if(ch=='h') cnt[0]++; if(ch=='a') if(cnt[1]<cnt[0]) cnt[1]++; if(ch=='p') if(cnt[2]<(cnt[1]<<1)) cnt[2]++; if(ch=='y') if(cnt[3]<(cnt[2]>>1)) cnt[3]++; } } void work(){ return; } void print(){ write(cnt[3]); return; } int main(){init();work();print();return 0;}
原来愚蠢的code:
#include<iostream> #include<cstdio> #include<cmath> #include<algorithm> #include<queue> #include<cstring> #define PAU putchar(' ') #define ENT putchar('\n') using namespace std; const int maxn=10000+10; int s[4][maxn],tot[4],cnt[4]; int check(int d,int t){ for(;cnt[d]<tot[d];cnt[d]++){ if(s[d][cnt[d]]>t) return s[d][cnt[d]]; } return -1; } inline int read(){ int x=0,sig=1;char ch=getchar(); while(!isdigit(ch)){if(ch=='-')sig=-1;ch=getchar();} while(isdigit(ch))x=10*x+ch-'0',ch=getchar(); return x*=sig; } inline void write(int x){ if(x==0){putchar('0');return;}if(x<0)putchar('-'),x=-x; int len=0,buf[15];while(x)buf[len++]=x%10,x/=10; for(int i=len-1;i>=0;i--)putchar(buf[i]+'0');return; } char ch; void init(){ int t=0; for(ch=getchar();isalpha(ch);ch=getchar()){ if(ch=='h') s[0][tot[0]++]=t++; else if(ch=='a') s[1][tot[1]++]=t++; else if(ch=='p') s[2][tot[2]++]=t++; else s[3][tot[3]++]=t++; } return; } int ans; void work(){ for(int i=0;i<tot[0];i++){ int t=s[0][i]; if((t=check(1,t))<0)break; if((t=check(2,t))<0)break; if((t=check(2,t))<0)break; if((t=check(3,t))<0)break; ans++; } return; } void print(){ write(ans); return; } int main(){init();work();print();return 0;}
相关文章推荐
- android常用框架 41-74
- swift ??
- Android Studio 插件(二)
- Android Studio 插件(一)
- Android Bundle类别
- swift tuple多元组
- Android下用OpenCV3.0库静态链接错误解决方法
- android onInterceptTouchEvent和onTouchEvent
- Android在ExpandableListView控制的基本使用
- Android 中延迟执行的小结
- Android访问数据库(SQL Server 和 MySQL)
- 补全开发大会上缺失的Apple和Google应用商店数据和比拼结果
- swift protocol mutating
- Android数据库SQLite使用详解二 : 学生管理系统的简单实现
- Android基础-实现有道词典实例
- android CountDownTimer
- 【麦可网】Cocos2d-X跨平台游戏开发学习笔记---第十二课:Cocos2D-X内存管理1-3
- cocos2d—x 常见错误
- Android启动画面
- poj 2385 Apple Catching dp