日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

pta-HASH--QQ账号与密码注册和登录

發布時間:2024/3/24 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 pta-HASH--QQ账号与密码注册和登录 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

輸入格式:

輸入首先給出一個正整數N),隨后給出N行指令。每行指令的格式為:“命令符(空格)QQ號碼(空格)密碼”。其中命令符為“N”(代表New)時表示要新申請一個QQ號,后面是新帳戶的號碼和密碼;命令符為“L”(代表Login)時表示是老帳戶登陸,后面是登陸信息。QQ號碼為一個不超過10位、但大于1000(據說QQ老總的號碼是1001)的整數。密碼為不小于6位、不超過16位、且不包含空格的字符串。

輸出格式:

針對每條指令,給出相應的信息:

1)若新申請帳戶成功,則輸出“New: OK”;2)若新申請的號碼已經存在,則輸出“ERROR: Exist”;3)若老帳戶登陸成功,則輸出“Login: OK”;4)若老帳戶QQ號碼不存在,則輸出“ERROR: Not Exist”;5)若老帳戶密碼錯誤,則輸出“ERROR: Wrong PW”。

輸入樣例:

5 L 1234567890 myQQ@qq.com N 1234567890 myQQ@qq.com N 1234567890 myQQ@qq.com L 1234567890 myQQ@qq L 1234567890 myQQ@qq.com

輸出樣例:

ERROR: Not Exist New: OK ERROR: Exist ERROR: Wrong PW Login: OK

這道題實際上O(n√ ̄n),688ms左右,hash表傳言O(1)查找,實際上不夠穩定,我寫的hash運行時間和map差不多。。。


1.線性表:平方探測處理沖突


#include<bits/stdc++.h> using namespace std; typedef long long ll; const int maxm=99997;//比表長10^5小的質數 const int maxn=110000;//平方探測法n太小容易找不到 !!!!一定要覆蓋全部數,大于n也要大于999999999%99997char op;//操作 struct p {ll qq;char ma[20];}; p hash1[maxn];//hash表 int DealConflict(p t,int index)//平方探測法處理沖突 {int temp;for(int i=0;i<=sqrt(maxn)+1;i++){if(i%2==1)//奇數加 {temp=index+(i/2+1)*(i/2+1);if(temp<maxn)//不越界 {if(hash1[temp].qq==0){return temp;}}}else//偶數減 {temp=index-(i/2)*(i/2);if(temp>=0)//不越界 {if(hash1[temp].qq==0){return temp;}} }}}void CreateHash(p t)//取模法建立hash {int temp=t.qq%maxm;int set=DealConflict(t,temp);hash1[set].qq=t.qq;strcpy(hash1[set].ma,t.ma);}int SearchHash(p t)//查找qq號 密碼匹配 {ll index=t.qq%maxm;int cur;for(int i=0;i<=sqrt(maxn)+1;i++){if(i%2==1)//奇數加 {cur=index+(i/2+1)*(i/2+1);if(cur<maxn)//不越界 {if(hash1[cur].qq==t.qq){if(strcmp(hash1[cur].ma,t.ma)==0)return 2;elsereturn 1;}}}else//偶數減 {cur=index-(i/2)*(i/2);if(cur>=0)//不越界 {if(hash1[cur].qq==t.qq){if(strcmp(hash1[cur].ma,t.ma)==0)return 2;elsereturn 1;}} }}return 0; }int main() { int n; cin>>n; p temp; while(n--) {cin>>op>>temp.qq>>temp.ma;if(op=='N'){if(SearchHash(temp)==1||SearchHash(temp)==2){cout<<"ERROR: Exist"<<endl;}else{cout<<"New: OK"<<endl;CreateHash(temp);}}else{if(SearchHash(temp)==0){cout<<"ERROR: Not Exist"<<endl;}else{if(SearchHash(temp)==1){cout<<"ERROR: Wrong PW"<<endl;}//elsecout<<"Login: OK"<<endl;}}}}

2.鏈表:類似鄰接表的結構(但不帶頭結點,因為初始化頭結點需要時間)

#include<bits/stdc++.h> using namespace std; typedef long long ll; const int maxm=99997;//比表長10^5小的質數? const int maxn=110000; vector<int>p; char op; struct q1 {ll qq;char ma[20];};struct q2 {ll qq;char ma[20];q2 *next;}Q; q2 *hash1[maxn];//void Init() //{ // hash1[cur]=new q2;// ?hash1[cur]->next=NULL; //} void Insert(q1 t)? {int cur=t.qq%maxm;q2 *s;s=new q2;s->qq=t.qq;strcpy(s->ma,t.ma);s->next=NULL;s->next=hash1[cur];hash1[cur]=s;}int Search(q1 t) {int cur=t.qq%maxm;if(hash1[cur]==NULL)//帶頭結點的話,初始化全部時間耗費大,所以不帶頭節點?return 0;q2 *s;s=hash1[cur];while(s!=NULL){if(s->qq==t.qq){if(strcmp(s->ma,t.ma)==0)return 2;elsereturn 1;}s=s->next;}//if(s==NULL)//空要馬上跳出,不然下面報錯? // return -1;return 0; }int main() {int n;cin>>n;q1 temp;for(int i=0;i<n;i++){cin>>op>>temp.qq>>temp.ma;if(op=='N'){if(Search(temp)==1||Search(temp)==2)cout<<"ERROR: Exist"<<endl;else?{cout<<"New: OK"<<endl;if(Search(temp)==0)Insert(temp);}}else{if(Search(temp)==0)cout<<"ERROR: Not Exist"<<endl;else if(Search(temp)==2)cout<<"Login: OK"<<endl;elsecout<<"ERROR: Wrong PW"<<endl;}}}

總結

以上是生活随笔為你收集整理的pta-HASH--QQ账号与密码注册和登录的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。