判断十二星座——我的算法,大家看是不是比较简便
2010-12-28 10:39
281 查看
#include <iostream>
#include <string>
using namespace std;
int main(){
int month=7, day=14;
string str[] = {
"水瓶座: 1月20日 - 2月18日",
"双鱼座: 2月19日 - 3月20日",
"白羊座: 3月21日 - 4月19日",
"金牛座: 4月20日 - 5月20日",
"双子座: 5月21日 - 6月21日",
"巨蟹座: 6月22日 - 7月22日",
"狮子座: 7月23日 - 8月22日",
"处女座: 8月23日 - 9月22日",
"天秤座: 9月23日 -10月23日",
"天蝎座: 10月24日 -11月22日",
"射手座: 11月23日 -12月21日",
"魔羯座: 12月22日 - 1月19日"
};
cout<<endl;
int arr[12] = { 20,19, 21, 20, 21, 22, 23, 23, 23, 24, 23, 22};
// for(int i=0;i<12;i++){
// cout<<str[i]<<endl;
// }cout<<endl;
cout<<"请输入月份:"<<endl;
cin>>month;
cout<<"请输入号:"<<endl;
cin>>day;
if(month<1||month>12||day<1||day>31){
cout<<"输入的日期有误"<<endl;
return -1;
}else {
cout<<"您输入的日期为:"<<month<<"月"<<day<<"日"<<endl;
}
if(day<arr[month-1]){
if(month==1) month=13;
cout<<str[month-2]<<endl;
}else {
cout<<str[month-1]<<endl;
}
return 0;
}
代码
#include <iostream>
#include <string>
using namespace std;
int main(){
int month=7, day=14;
string str[] = {
"水瓶座: 1月20日 - 2月18日",
"双鱼座: 2月19日 - 3月20日",
"白羊座: 3月21日 - 4月19日",
"金牛座: 4月20日 - 5月20日",
"双子座: 5月21日 - 6月21日",
"巨蟹座: 6月22日 - 7月22日",
"狮子座: 7月23日 - 8月22日",
"处女座: 8月23日 - 9月22日",
"天秤座: 9月23日 -10月23日",
"天蝎座: 10月24日 -11月22日",
"射手座: 11月23日 -12月21日",
"魔羯座: 12月22日 - 1月19日"
};
cout<<endl;
int arr[12] = { 20,19, 21, 20, 21, 22, 23, 23, 23, 24, 23, 22};
// for(int i=0;i<12;i++){
// cout<<str[i]<<endl;
// }cout<<endl;
cout<<"请输入月份:"<<endl;
cin>>month;
cout<<"请输入号:"<<endl;
cin>>day;
if(month<1||month>12||day<1||day>31){
cout<<"输入的日期有误"<<endl;
return -1;
}else {
cout<<"您输入的日期为:"<<month<<"月"<<day<<"日"<<endl;
}
if(day<arr[month-1]){
if(month==1) month=13;
cout<<str[month-2]<<endl;
}else {
cout<<str[month-1]<<endl;
}
return 0;
}
#include <string>
using namespace std;
int main(){
int month=7, day=14;
string str[] = {
"水瓶座: 1月20日 - 2月18日",
"双鱼座: 2月19日 - 3月20日",
"白羊座: 3月21日 - 4月19日",
"金牛座: 4月20日 - 5月20日",
"双子座: 5月21日 - 6月21日",
"巨蟹座: 6月22日 - 7月22日",
"狮子座: 7月23日 - 8月22日",
"处女座: 8月23日 - 9月22日",
"天秤座: 9月23日 -10月23日",
"天蝎座: 10月24日 -11月22日",
"射手座: 11月23日 -12月21日",
"魔羯座: 12月22日 - 1月19日"
};
cout<<endl;
int arr[12] = { 20,19, 21, 20, 21, 22, 23, 23, 23, 24, 23, 22};
// for(int i=0;i<12;i++){
// cout<<str[i]<<endl;
// }cout<<endl;
cout<<"请输入月份:"<<endl;
cin>>month;
cout<<"请输入号:"<<endl;
cin>>day;
if(month<1||month>12||day<1||day>31){
cout<<"输入的日期有误"<<endl;
return -1;
}else {
cout<<"您输入的日期为:"<<month<<"月"<<day<<"日"<<endl;
}
if(day<arr[month-1]){
if(month==1) month=13;
cout<<str[month-2]<<endl;
}else {
cout<<str[month-1]<<endl;
}
return 0;
}
代码
#include <iostream>
#include <string>
using namespace std;
int main(){
int month=7, day=14;
string str[] = {
"水瓶座: 1月20日 - 2月18日",
"双鱼座: 2月19日 - 3月20日",
"白羊座: 3月21日 - 4月19日",
"金牛座: 4月20日 - 5月20日",
"双子座: 5月21日 - 6月21日",
"巨蟹座: 6月22日 - 7月22日",
"狮子座: 7月23日 - 8月22日",
"处女座: 8月23日 - 9月22日",
"天秤座: 9月23日 -10月23日",
"天蝎座: 10月24日 -11月22日",
"射手座: 11月23日 -12月21日",
"魔羯座: 12月22日 - 1月19日"
};
cout<<endl;
int arr[12] = { 20,19, 21, 20, 21, 22, 23, 23, 23, 24, 23, 22};
// for(int i=0;i<12;i++){
// cout<<str[i]<<endl;
// }cout<<endl;
cout<<"请输入月份:"<<endl;
cin>>month;
cout<<"请输入号:"<<endl;
cin>>day;
if(month<1||month>12||day<1||day>31){
cout<<"输入的日期有误"<<endl;
return -1;
}else {
cout<<"您输入的日期为:"<<month<<"月"<<day<<"日"<<endl;
}
if(day<arr[month-1]){
if(month==1) month=13;
cout<<str[month-2]<<endl;
}else {
cout<<str[month-1]<<endl;
}
return 0;
}
相关文章推荐
- 判断十二星座——我的算法,大家看是不是比较简便
- 判断质数的优化算法,比较详细解释
- 判断一个数是不是2的N次方,很牛的算法#define ISPOW2(x) (x) & (x-1) ? false : true
- 算法—判断整数序列是不是二元查找树的后序遍历结果
- 算法-判断整数序列是不是二元查找树的后序遍历结果
- 判断一个数是不是2的N次方 自己写的土算法
- 每天一算法(判断该数组是不是某二元查找树的后序遍历的结果)
- 字符串操作(人民币转成大写/全角字符转半角字符/去掉字符串中重复的子字符串/过滤常见特殊字符/反过滤特殊字符/判断是不是合法手机/字符串匹配的算法)
- 判断句子是不是魔法咒语的算法
- 代码技巧1.类似于登录、注册界面要判断登录账号是不是空,验证码是否正确等,怎么写比较舒服一点?
- 【算法-java】判断该数组是不是某二叉搜索树的后序遍历的结果
- 判断句子是不是魔法咒语的算法
- 判断两个字串是不是回文构词(算法)
- 判断一个二叉树是不是平衡的(算法)
- 算法--判断字符串是不是数字
- 目前互联网上公布出来的正文提取算法,大家可以综合比较下,一起来测试下哪个更好用。 词网--北京词网科技有限公司 http://demo.cikuu.com/cgi-bin/cgi-contex 猎兔网页正文提取 http://www.lie
- 微软算法100道题-----判断整数序列是不是二元查找树的后序遍历结果
- 利用while循环翻转数字之后,比较翻转后的数字是否与原来的数字相同的方法来判断是不是回文数字
- 算法:如何判断平面上的四个点是不是组成一个矩形
- 【经典算法】:判断一个字符串是不是标志符的算法实现