Advertisement
Guest User

Untitled

a guest
Apr 30th, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.33 KB | None | 0 0
  1. #include<iostream>
  2. #include<string>
  3. #include<stdlib.h>
  4. #include<time.h>
  5. #include<windows.h>
  6. using namespace std;
  7. char randomletter()
  8. {
  9. int a;
  10. char b;
  11. //srand(time(NULL));
  12. a=rand()%26;
  13. b='A'+a;
  14. return b;
  15. }
  16. char randomsex()
  17. {
  18. int x;
  19. char y;
  20. //srand(time(NULL));
  21. x=rand()%2;
  22. y='1'+x;
  23. return y;
  24. }
  25. char randomnum()
  26. {
  27. int z;
  28. char w;
  29. //srand(time(NULL));
  30. z=rand()%10;
  31. w='0'+z;
  32. return w;
  33. }
  34. int letter_to_number(char c)
  35. {
  36. if('A'<=c&&c<='Z')return c-'A';
  37. if('a'<=c&&c<='z')return c-'a';
  38. return c-'0';
  39. }
  40. int main()
  41. {
  42. srand(time(NULL)); //srand是加在程式最前面的
  43. int num,total;
  44. char i[15],j[15];
  45. 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};
  46. cout<<"歡迎來到身分證產生器"<<endl;
  47. cout<<"請輸入你想要幾組:";
  48. cin>>num;
  49. system("CLS");
  50. cout<<"A台北市 B台中市 C基隆市 D台南市 E高雄市 F台北縣 G宜蘭縣 H桃園縣 I嘉義市"<<endl;
  51. cout<<"J新竹縣 K苗栗縣 L台中縣 M南投縣 N彰化縣 O新竹市 P雲林縣 Q嘉義縣 R台南縣"<<endl;
  52. cout<<"S高雄縣 T屏東縣 U花蓮縣 V台東縣 W金門縣 X澎湖縣 Y陽明山 Z連江縣"<<endl;
  53. cout<<"請輸入縣市代碼,隨機請按0:";
  54. cin>>i[0];
  55. system("CLS");
  56. if(i[0]>='a'&&i[0]<='z')
  57. {
  58. i[0]=i[0]-'a'+'A';
  59. }
  60. cout<<"male:1 female:2 random:3"<<endl;
  61. cout<<"請輸入性別代碼:";
  62. while(cin>>i[1])//bug
  63. { if(i[1]>'3'||i[1]<'1')
  64. {
  65. cout<<"fuck!!!"<<endl;
  66. cout<<"請再輸入一次:";
  67. }
  68. else break;
  69. }
  70. system("CLS");
  71. for(int k=1;k<=num;k++) //個數{}
  72. {
  73. total=0;
  74. if(i[0]=='0') //隨機字母+換成數字
  75. {
  76. i[0]=randomletter();
  77. int x=letter_to_number(i[0]);
  78. total=total+(x%10*9)+x/10;
  79. //j[0]=i[0];
  80. //j[0]=p[i[0]-'A'];
  81. //j[0]=(j[0]%10)*9+j[0]/10;
  82. }
  83. if(i[1]=='3') //隨機性別
  84. {
  85. i[1]=randomsex();
  86. }
  87. for(int n=2;n<=8;n++) //產生身分證的2~9碼
  88. {
  89. i[n]=randomnum();
  90. int x=letter_to_number(i[n]);
  91. total=total+x*(10-n);
  92. //j[n]=i[n];
  93. }
  94. /*for(int m=1;m<=8;m++) //乘上數字
  95. {
  96. j[m]=j[m]*(9-m);
  97. }
  98. for(int l=0;l<=8;l++) //total
  99. {
  100. total=total+j[l];
  101. }*/
  102. cout<<total<<endl;
  103. i[9]=(char)((total%10)+'0'); //你忘了換char
  104. cout<<i<<endl;
  105. }
  106.  
  107. return 0;
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement