Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<string>
- #include<stdlib.h>
- #include<time.h>
- #include<windows.h>
- using namespace std;
- char randomletter()
- {
- int a;
- char b;
- //srand(time(NULL));
- a=rand()%26;
- b='A'+a;
- return b;
- }
- char randomsex()
- {
- int x;
- char y;
- //srand(time(NULL));
- x=rand()%2;
- y='1'+x;
- return y;
- }
- char randomnum()
- {
- int z;
- char w;
- //srand(time(NULL));
- z=rand()%10;
- w='0'+z;
- return w;
- }
- int letter_to_number(char c)
- {
- if('A'<=c&&c<='Z')return c-'A';
- if('a'<=c&&c<='z')return c-'a';
- return c-'0';
- }
- int main()
- {
- srand(time(NULL)); //srand是加在程式最前面的
- int num,total;
- char i[15],j[15];
- int p[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};
- cout<<"歡迎來到身分證產生器"<<endl;
- cout<<"請輸入你想要幾組:";
- cin>>num;
- system("CLS");
- cout<<"A台北市 B台中市 C基隆市 D台南市 E高雄市 F台北縣 G宜蘭縣 H桃園縣 I嘉義市"<<endl;
- cout<<"J新竹縣 K苗栗縣 L台中縣 M南投縣 N彰化縣 O新竹市 P雲林縣 Q嘉義縣 R台南縣"<<endl;
- cout<<"S高雄縣 T屏東縣 U花蓮縣 V台東縣 W金門縣 X澎湖縣 Y陽明山 Z連江縣"<<endl;
- cout<<"請輸入縣市代碼,隨機請按0:";
- cin>>i[0];
- system("CLS");
- if(i[0]>='a'&&i[0]<='z')
- {
- i[0]=i[0]-'a'+'A';
- }
- cout<<"male:1 female:2 random:3"<<endl;
- cout<<"請輸入性別代碼:";
- while(cin>>i[1])//bug
- { if(i[1]>'3'||i[1]<'1')
- {
- cout<<"fuck!!!"<<endl;
- cout<<"請再輸入一次:";
- }
- else break;
- }
- system("CLS");
- for(int k=1;k<=num;k++) //個數{}
- {
- total=0;
- if(i[0]=='0') //隨機字母+換成數字
- {
- i[0]=randomletter();
- int x=letter_to_number(i[0]);
- total=total+(x%10*9)+x/10;
- //j[0]=i[0];
- //j[0]=p[i[0]-'A'];
- //j[0]=(j[0]%10)*9+j[0]/10;
- }
- if(i[1]=='3') //隨機性別
- {
- i[1]=randomsex();
- }
- for(int n=2;n<=8;n++) //產生身分證的2~9碼
- {
- i[n]=randomnum();
- int x=letter_to_number(i[n]);
- total=total+x*(10-n);
- //j[n]=i[n];
- }
- /*for(int m=1;m<=8;m++) //乘上數字
- {
- j[m]=j[m]*(9-m);
- }
- for(int l=0;l<=8;l++) //total
- {
- total=total+j[l];
- }*/
- cout<<total<<endl;
- i[9]=(char)((total%10)+'0'); //你忘了換char
- cout<<i<<endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement