zoukankan      html  css  js  c++  java
  • 判断十二星座——我的算法,大家看是不是比较简便

    #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;
    }
  • 相关阅读:
    程序员小抄大全
    赢在中国“80后30个忠告”
    Eclipse下python插件(pydev)的安装
    PDF加密文件的解密和打印
    中美欧联手打击僵尸网络 深化安全合作 狼人:
    入侵奥巴马帐号法国黑客自称是一个好黑客 狼人:
    Firefox 3.6.3版率先修复黑客大赛所曝漏洞 狼人:
    2009年全球安全SaaS市场收入比2008年增长70% 狼人:
    微软等厂商高管谈安全云面临的挑战 狼人:
    报告称Windows7不安全 管理员权限是罪魁祸首 狼人:
  • 原文地址:https://www.cnblogs.com/sdlypyzq/p/1918698.html
Copyright © 2011-2022 走看看