poj2328---"right on"进入下一个case的模板(while)
2015-06-13 12:04
253 查看
#include <stdio.h> #include <stdlib.h> #include<string.h> int main() { char str[10]; int n,begin=0,end=11; while(scanf("%d",&n) && n)//以0结束的可以由这种格式写 { getchar();//读取缓冲区的东西 gets(str); if(!strcmp(str,"too low") && n>begin)//猜数的人傻,加后面那个条件说明他每一次都像第一次猜 { begin=n; } if(!strcmp(str,"too high") && n<end) { end=n; } if(!strcmp(str,"right on")) { if(n<end && n>begin) { printf("Stan may be honest"); } else { printf("Stan is dishonest"); } begin=0;end=11;//初始化条件 continue; } } return 0; }
总结:gets之前如果用了scanf,中间要用getchar
scanf不能用来读并且存储包含空格的串,用gets,但之前一定用getchar清除缓冲区的杂碎
10 too high 3 too low 4 too high 2 right on 5 too low 7 too high 6 right on 0 这种输入的模板代码,read above
相关文章推荐
- Linux ld命令
- Xcode 7.0 beta中OC的语法更新
- Linux中基于apache httpd的svn服务器搭建与配置
- memcached 之 哈希一致性 和 虚拟节点 分析
- X86函数内存栈
- Valid Palindrome 判断回文字符串
- C语言的左位移能不能超过8位?
- kettle初探
- Linux下安装Memcached图解教程
- 强连通分量分解
- First Missing Positive
- mysql win源码比较大 不需要的文件删除 记录下来
- 每天睡6小时和8小时区别有多大,看完再也不敢熬夜了
- 微软2014校园招聘笔试试题
- java异常概述
- 九鼎创展s5p4418开发板Android4.4-文件系统编译脚本分析
- beego模板语法 go语言模版语法
- epoll模型的理解封装与应用
- malloc 函数和new的区别
- 关于spring 整合 hibernate 事务不回滚