Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // HW1 Password Inspection System
- #include <iostream>
- #include <cstdio>
- #include <cstdlib>
- #include <cstring>
- using namespace std;
- #define MAX_STRING 20
- int main()
- {
- char str1[MAX_STRING];
- char str2[MAX_STRING];
- char str3[MAX_STRING];
- //string test1;
- //string test2;
- char c;
- int count = 3;
- int i=0;
- int z=0;
- int x=0;
- do{
- cout << "Please input password --> ";
- gets(str1);
- int len=strlen(str1);
- for(z=0;z<=len;z++)
- {
- if( str1[z]!=' ')
- str1[x++] = str1[z];
- }
- str1[x]='\0';
- for(i=1;i<4;i++)
- {
- cout << "------Password Inspection System----- \n";
- cout << "Please input password to inspect--> ";
- gets(str2);
- int len=strlen(str2);
- //把空白字元取代
- for(x=0,z=0;z<=len;z++)
- {
- if( str2[z]!=' ')
- str2[x++] = str2[z];
- }
- str2[x]='\0';
- cout<<str2<<endl;
- if(!strcmp(str1,str2))
- {
- cout << "your password is right \n";
- break;
- }
- else
- {
- count--;
- cout << "your password is wrong,please input password again!!! \n";
- cout << "(you have only " << count <<" times to input!!!) \n";
- continue;
- }
- //cout << "you have no chance!!! \n";
- }
- cout << "continue ??? (if want to continue, input 'y')\n";
- cin >> c;
- }while(c == 'y');
- system("pause");
- return 0;
- }
Add Comment
Please, Sign In to add comment