poj1250
2013-03-15 13:10
120 查看
简单题
View Code
View Code
#include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> using namespace std; #define maxl 60 int n; char st[maxl]; bool have_bed[maxl]; bool occured[maxl]; int hash(char ch) { return ch - 'A'; } int work() { int len = strlen(st); int ans = 0; for (int i = 0; i < len; i++) if (!occured[hash(st[i])]) { occured[hash(st[i])] = true; if (n > 0) { have_bed[hash(st[i])] = true; n--; }else ans++; }else { if (have_bed[hash(st[i])]) { have_bed[hash(st[i])] = false; n++; } } return ans; } int main() { //freopen("t.txt", "r", stdin); while (scanf("%d", &n), n) { scanf("%s", st); memset(have_bed, 0, sizeof(have_bed)); memset(occured, 0, sizeof(occured)); int ans = work(); if (ans == 0) puts("All customers tanned successfully."); else printf("%d customer(s) walked away.\n", ans); } return 0; }
相关文章推荐
- [leetcode] convert sorted list to binary search
- 一些人对算法的一些感悟
- ubuntu 常遇到的问题
- 云计算之路-迁入阿里云后:问题的根源——买到她的“人”,却买不到她的“心”
- 左右两列布局
- Cocos2d-x 绘制动画
- C#模拟拦截器的实现
- HelloWorldForU ---九度Online Judge
- HelloWorldForU ---九度Online Judge
- c++智能指针的创建[转载]
- hadoop搭建教程之四(Hive安装)
- 如何在多台机器上共享IOS证书
- 提示 指定的服务未安装 unable to open the service 'tomcat7'
- eclipse 中 按 ctrl+shift+f 格式化代码时,每行容纳的字符数
- Eclipse 运行 android 项目的问题
- 基于数据库的企业级智能表单系统设计(asp.net)-序言
- 写给当下的软件工程师————感悟篇
- 对printf和cout一点理解
- ExtJs ArrayGrid简单例子
- 转:深入理解abstract class和interface