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