PJ-T3成功地给我上了一课
MAP映射——万物皆可映射
赛后代码
#include<bits/stdc++.h>
using namespace std;
int T,a,b,c,d,e;
char s[35];
map<long long,int> q;
inline int l(int x){
if(!x) return 1;
int tot=0;
while (x) x/=10,tot++;
return tot;
}
inline long long getsum(){ //25525525525565535不会爆long long,用个map不错
int tot=e;
tot*=100000;tot+=d;tot*=1000;tot+=c;tot*=1000;tot+=b;tot*=1000;tot+=a;tot*=1000;
return tot;
}
int main(){
scanf("%d",&T);
for(int i=1;i<=T;i++){
string ch;
a=b=c=d=e=-1;
cin>>ch>>s;
sscanf(s,"%d.%d.%d.%d:%d",&a,&b,&c,&d,&e);
if(a==-1||b==-1||c==-1||d==-1||e==-1||a>255||b>255||c>255||d>255||e>65535){
puts("ERR");
continue;
}
if(l(a)+l(b)+l(c)+l(d)+l(e)+4!=strlen(s)){
puts("ERR");
continue;
}
int sum=getsum();
if(ch[0]=='S'){
if(!q[sum]){
q[sum]=i;
puts("OK");
continue;
}else{
puts("FAIL");
continue;
}
}else{
if(q[sum]){
printf("%d\n",q[sum]);
continue;
}else{
puts("FAIL");
continue;
}
}
}
return 0;
}
PS:赛时代码200行——65pts
原来几十行能搞定的事情啊…
学map,sscanf去…