会了组成原理,这就道水题
详见https://wenku.baidu.com/view/6ad6e27f76c66137ee061990.html
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[(1<<6)+1];
char s[100];
int main()
{
// freopen("data.txt","r",stdin);
// ios_base::sync_with_stdio(false);
ll ct=0,ct1=0;
for(int i=0;i<(1<<6);i++)
{
a[i]=-1;
}
while(~scanf("%s",s))
{
if(strcmp(s,"END")==0)
break;
ct++;
int len=strlen(s);
ll sum=0;
ll t = 1;
for(int i=len-1;i>=0;i--)
{
if(s[i]>='0'&&s[i]<='9')
{
sum += (s[i]-48)*t;
}
else if(s[i]>='A'&&s[i]<='F')
{
sum += (s[i]-55)*t;
}
t*=16;
}
// cout << sum<<endl;
ll t1 = sum/(1<<10);
sum%=(1<<10);
ll tt = sum>>4;
sum%=64;
if(a[tt]==-1)
{
printf("Miss\n");
a[tt] =t1;
}
else
{
if(a[tt]==t1)
{
ct1++;
printf("Hit\n");
}
else
{
printf("Miss\n");
a[tt] =t1;
}
}
}
printf("Hit ratio = %.2lf%%\n",(double)ct1/(double)ct*100);
return 0;
}