判断十二星座——我的算法,大家看是不是比较简便

8 篇文章 0 订阅
7 篇文章 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 < 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 ;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

张欣-男

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值