返回列表 發帖
本帖最後由 johnsom127 於 2010-8-24 15:19 編輯

版權所有 請勿翻印
翻印者須負法律責任
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <math.h>
  4. using namespace std;
  5. int main(void){
  6.     char town;
  7.     int sex;
  8.     int check[26] = { 10, 11, 12, 13, 14, 15, 16, 17, 34, 18, 19, 20, 21,
  9.                       22, 35, 23, 24, 25, 26, 27, 28, 29, 32, 30, 31, 33};
  10.     while(cout <<"請輸入居住城市代碼 : "<<endl
  11.                <<"A台北市 J新竹縣 S高雄縣 B台中市 K苗栗縣 T屏東縣 C基隆市 L台中縣 U花蓮縣"<<endl
  12.                <<"D台南市 M南投縣 V台東縣 E高雄市 N彰化縣 W金門縣 F台北縣 O新竹市 X澎湖縣"<<endl
  13.                <<"G宜蘭縣 P雲林縣 Y陽明山 H桃園縣 Q嘉義縣 Z連江縣 I嘉義市 R台南縣"<<endl){
  14.                
  15.                string id;
  16.                srand(time(NULL)); // 下亂數種子
  17.                cin >>town;
  18.                if(town >=97 &&town <=122){
  19.                        id +=town-32;        
  20.                }else if(town >=65 &&town <=90){
  21.                      id +=town;      
  22.                }else{
  23.                      for(int i=0;i<1001;i++){
  24.                              cout<<"恭喜你中獎了!!";
  25.                      }
  26.                      cout<<"請重新輸入";      
  27.                }
  28.                cout <<"請輸入性別 : (1:男 2:女)";
  29.                cin >> sex;
  30.                if(sex ==1){
  31.                       id +='1';
  32.                }else if(sex ==2){
  33.                      id +='1';
  34.                }else{
  35.                      for(int i=0;i<1001;i++){
  36.                              cout<<"恭喜你中獎了!!";
  37.                      }
  38.                      cout<<"請重新輸入";
  39.                }
  40.                for (int i = 1; i <= 7; i++){
  41.                         id += (char)((rand()*15217%10)+48);
  42.                }
  43.                cout <<id
  44.                     <<10-((check[id[0]-64]/10 + check[id[0]-64]%10*9 + (id[2]-48)*8+
  45.                     + (id[3]-48)*7+ (id[4]-48)*6+ (id[5]-48)*5
  46.                     + (id[6]-48)*4+ (id[7]-48)*3+ (id[8]-48)*2+ (id[9]-48))%10)
  47.                     +(((check[id[0]-64]/10 + check[id[0]-64]%10*9 + (id[2]-48)*8+
  48.                     + (id[3]-48)*7+ (id[4]-48)*6+ (id[5]-48)*5
  49.                     + (id[6]-48)*4+ (id[7]-48)*3+ (id[8]-48)*2+ (id[9]-48))%10) ==0)*(-10)
  50.                     <<endl<<"___________________________________________________________"<<endl;
  51.                                 
  52.     }
  53. system("pause");
  54. return 0;
  55. }
複製代碼
我是吳先生SIR

TOP

返回列表