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

#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;
}

 

posted on 2010-12-28 10:39  cv_ml_张欣男  阅读(719)  评论(3编辑  收藏  举报

导航