hdu-2617
Happy 2009
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2439 Accepted Submission(s): 819
Problem Description
No matter you know me or not. Bless you happy in 2009.
Input
The input contains multiple test cases.
Each test case included one string. There are made up of ‘a’-‘z’ or blank. The length of string will not large than 10000.
Each test case included one string. There are made up of ‘a’-‘z’ or blank. The length of string will not large than 10000.
Output
For each test case tell me how many times “happy” can be constructed by using the string. Forbid to change the position of the characters in the string. The answer will small than 1000.
Sample Input
hopppayppy happy happ acm y hahappyppy
Sample Output
2 1 2此题我竟然没做出来,想想我都想哭,我水平怎么这么水。。。。#include<stdio.h> #include<string.h> int main() { char string[10012]; int k,i,j; //getchar(); while(gets(string)!=NULL) { int a,b,c1,c2,d; a=0;b=0;c1=0;c2=0;d=0; k=strlen(string); for(i=0;i<k;i++) { if(string[i]=='h') a++; else if(string[i]=='a'&&a>0) { a--; b++; } else if(string[i]=='p') { if(c1>0) { c1--; c2++; } else if(b>0) { b--; c1++; } } else if(string[i]=='y'&&c2>0) { c2--; d++; } } printf("%d\n",d); } return 0; } 用的别人的思路。。。 比较好理解
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· 终于写完轮子一部分:tcp代理 了,记录一下
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理