Guest User

Untitled

a guest
Jan 19th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. // HW1 Password Inspection System
  2.  
  3. #include <iostream>
  4. #include <cstdio>
  5. #include <cstdlib>
  6. #include <cstring>
  7. using namespace std;
  8.  
  9. #define MAX_STRING 20
  10.  
  11.  
  12. int main()
  13. {
  14. char str1[MAX_STRING];
  15. char str2[MAX_STRING];
  16. char str3[MAX_STRING];
  17. //string test1;
  18. //string test2;
  19. char c;
  20. int count = 3;
  21. int i=0;
  22. int z=0;
  23. int x=0;
  24.  
  25. do{
  26.  
  27. cout << "Please input password --> ";
  28. gets(str1);
  29. int len=strlen(str1);
  30. for(z=0;z<=len;z++)
  31. {
  32. if( str1[z]!=' ')
  33. str1[x++] = str1[z];
  34. }
  35. str1[x]='\0';
  36.  
  37. for(i=1;i<4;i++)
  38. {
  39. cout << "------Password Inspection System----- \n";
  40. cout << "Please input password to inspect--> ";
  41. gets(str2);
  42. int len=strlen(str2);
  43. //把空白字元取代
  44. for(x=0,z=0;z<=len;z++)
  45. {
  46. if( str2[z]!=' ')
  47. str2[x++] = str2[z];
  48. }
  49. str2[x]='\0';
  50. cout<<str2<<endl;
  51.  
  52. if(!strcmp(str1,str2))
  53.  
  54. {
  55. cout << "your password is right \n";
  56. break;
  57. }
  58. else
  59. {
  60. count--;
  61. cout << "your password is wrong,please input password again!!! \n";
  62. cout << "(you have only " << count <<" times to input!!!) \n";
  63. continue;
  64. }
  65. //cout << "you have no chance!!! \n";
  66. }
  67. cout << "continue ??? (if want to continue, input 'y')\n";
  68. cin >> c;
  69. }while(c == 'y');
  70.  
  71. system("pause");
  72. return 0;
  73. }
Add Comment
Please, Sign In to add comment