博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
一段有趣的代码,猜生日
阅读量:6858 次
发布时间:2019-06-26

本文共 2538 字,大约阅读时间需要 8 分钟。

  hot3.png

转自:http://www.oschina.net/code/snippet_10896_2907

[代码] GuessBirthDate.cpp

/** * 一段有趣的代码,猜生日。 * 运行程序,做5次选择,就能知道你的生日是哪一天。神奇! */#include 
using namespace std;int main(){ int date = 0; // Date to be determind char answer; // Prompt the user for Set 1 cout << "Is your birth date in this set ?" << endl; cout << "16 17 18 19/n" << "20 21 22 23/n" << "24 25 26 27/n" << "28 29 30 31" << endl; cout << "Enter N for No and Y for Yes: "; cin >> answer; if (answer == 'Y') date += 16; // Prompt the user for Set 2 cout << "Is your birth date in this set ?" << endl; cout << " 8 9 10 11/n" << "12 13 14 15/n" << "24 25 26 27/n" << "28 29 30 31" << endl; cout << "Enter N for No and Y for Yes: "; cin >> answer; if (answer == 'Y') date += 8; // Prompt the user for Set 3 cout << "Is your birth date in this set ?" << endl; cout << " 1 3 5 7/n" << " 9 11 13 15/n" << "17 19 21 23/n" << "25 27 29 31" << endl; cout << "Enter N for No and Y for Yes: "; cin >> answer; if (answer == 'Y') date += 1; // Prompt the user for Set 4 cout << "Is your birth date in this set ?" << endl; cout << " 2 3 6 7/n" << "10 11 14 15/n" << "18 19 22 23/n" << "26 27 30 31" << endl; cout << "Enter N for No and Y for Yes: "; cin >> answer; if (answer == 'Y') date += 2; // Prompt the user for Set 5 cout << "Is your birth date in this set ?" << endl; cout << " 4 5 6 7/n" << "12 13 14 15/n" << "20 21 22 23/n" << "28 29 30 31" << endl; cout << "Enter N for No and Y for Yes: "; cin >> answer; if (answer == 'Y') date += 4; cout << "Your birth date is " << date << endl; return 0;}

 

[代码] 测试我的生日

david@xmimx:GuessBirthDate$ ./GuessBirthDate Is your birth date in this set ?16 17 18 1920 21 22 2324 25 26 2728 29 30 31Enter N for No and Y for Yes: NIs your birth date in this set ? 8  9 10 1112 13 14 1524 25 26 2728 29 30 31Enter N for No and Y for Yes: YIs your birth date in this set ? 1  3  5  7 9 11 13 1517 19 21 2325 27 29 31Enter N for No and Y for Yes: NIs your birth date in this set ? 2  3  6  710 11 14 1518 19 22 2326 27 30 31Enter N for No and Y for Yes: NIs your birth date in this set ? 4  5  6  712 13 14 1520 21 22 2328 29 30 31Enter N for No and Y for Yes: YYour birth date is 12

转载于:https://my.oschina.net/dake/blog/196705

你可能感兴趣的文章
div+css实现的左右两个等高div
查看>>
Linux学习笔记-忘了第几天了:简单的用户管理命令
查看>>
教你3分钟搞定Linux正则表达式
查看>>
& 号和管道符号(|)在不同场景下的使用方法
查看>>
cssSourceMap: true 的作用
查看>>
app定位经纬度出现5e-324的情况
查看>>
是什么让程序员成了一份苦逼的工作?
查看>>
程序员如何做好应聘?简历、面试和Offer
查看>>
阿里云MVP课堂:零基础建站,满足你拥有自己网站的心愿
查看>>
(十七) 整合spring cloud云架构 -消息驱动 Spring Cloud Stream
查看>>
mysql主从同步,安装配置操作
查看>>
推荐:并发情况下:Java HashMap 形成死循环的原因
查看>>
C++ unordered_map using a custom class type as the key
查看>>
Nginx 常见设置之用户认证
查看>>
<!DOCTYPE html>很重要
查看>>
Spring Cloud 入门教程3、服务消费者(Feign)
查看>>
BIOS 中英文对照表
查看>>
SpringMVC返回值的几种方式
查看>>
综合实验DM***+EZ***+Eigrp&OSPF+路由重发布
查看>>
Cisco AP 胖瘦互转
查看>>