#include<iostream>
#include<cstdio>
#include<string.h>
using namespace std;
#define N 100010
#define M 100000
struct QQ
{
char Acnumber[15];
char Password[20];
int state;
}A[N];
int Hash(char Acnumber[], char Password[], char c )
{
int address = 0;
int s; // L 1:存在且密码正确 0:不存在 -1:存在但密码错误.
// N 1:不存在且创建成功 0:存在
int l = strlen( Acnumber );
if( l <= 6)
for( int i = 0; i < l; i++ )
address = address *10 + ( Acnumber[i] - '0');
else
for( int i = l-6; i < l; i++ )
address = address *10 + ( Acnumber[i] - '0' );
// Find
if( c == 'L')
{
s = 0;
for( int i = 0; i < M; i++ )
{
int j =( address + i ) % M;
if( A[j].state == 0 )
break;
if( strcmp( A[j].Acnumber, Acnumber ) == 0 )
{
if( strcmp( A[j].Password, Password ) == 0 )
s = 1;
else
s = -1;
break;
}
}
}
else if( c == 'N')
{
s = 0;
for( int i = 0; i < M; i++ )
{
int j =( address + i ) % M;
if( strcmp( A[j].Acnumber, Acnumber ) == 0 )
break;
if( A[j].state == 0 )
{
s = 1;
A[j].state = 1;
strcpy( A[j].Acnumber, Acnumber );
strcpy( A[j].Password, Password );
break;
}
}
}
return s;
}
int main()
{
int n;
char state;
char acnumber[15];
char password[20];
cin >> n;
while( n-- )
{
cin >> state >> acnumber >> password;
if( state == 'L')
{
int s = Hash( acnumber, password, 'L' );
if( s == 1 )
cout << "Login: OK" << endl;
else if( s == 0)
cout << "ERROR: Not Exist" << endl;
else if( s == -1 )
cout << "ERROR: Wrong PW" << endl;
}
else if( state == 'N')
{
int s = Hash( acnumber, password, 'N' );
if( s == 1)
cout << "New: OK" << endl;
else if( s == 0 )
cout << "ERROR: Exist" << endl;
}
}
return 0;
}
散列3 QQ帐户的申请与登陆
最新推荐文章于 2023-08-01 15:54:18 发布