判断十二星座——我的算法,大家看是不是比较简便
2013-04-10 22:25
316 查看
#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;
}
相关文章推荐
- 判断十二星座——我的算法,大家看是不是比较简便
- 【算法】判断整数序列是不是二元查找树的后序遍历结果
- 通过在jsp页面中比较主机服务器名的方式判断网页表单是不是外部提交方法
- [算法问题]判断一个数是不是2的幂?
- 每天一道算法题5 判断整数序列是不是二元查找树的后序遍历结果
- 目前互联网上公布出来的正文提取算法,大家可以综合比较下
- 判断一个点是不是在三角形中 用面积算法
- 判断一个比较大的数是不是素数的方式(最简单的)
- [算法]判断一个数是不是2的N次方
- 算法与数据结构面试题(8)-判断整数序列是不是二元查找树的后序遍历结果
- 每日一道算法题6——判断整数序列是不是二元查找树的后序遍历结果
- 算法讨论(五)--判断整数序列是不是二元查找树的后序遍历结果
- 判断质数的优化算法,比较详细解释
- 算法--两个数大小比较,不用分支判断
- 判断一个数是不是2的N次方,很牛的算法#define ISPOW2(x) (x) & (x-1) ? false : true
- 算法—判断整数序列是不是二元查找树的后序遍历结果
- 判断一个数是不是2的N次方 自己写的土算法
- 算法-判断整数序列是不是二元查找树的后序遍历结果
- 每天一算法(判断该数组是不是某二元查找树的后序遍历的结果)
- 判断句子是不是魔法咒语的算法