C语言航空公司VIP客户查询
发布网友
发布时间:2022-04-20 21:27
我来回答
共2个回答
热心网友
时间:2023-11-04 12:27
#include <map>
#include <vector>
#include <string>
#include <iostream>
using namespace std;
int main()
{
map<string, unsigned int> mapAOV;
map<string, unsigned int>::iterator iterCur, iterEnd;
long long llRecoder = 0ll;
unsigned int unK = 0u;
unsigned int unSumKM = 0u;
long long i = 0;
string strID = "";
char chID[19] = "";
while (TRUE)
{
cin >> llRecoder >> unK;
if (unK > 500) continue;
break;
}
while (i < llRecoder)
{
cin >> chID >> unSumKM;
if (chID[17] < '0' || chID[17] > '9')
{
if (chID[17] != 'x')
{
cout << "RecoderID format error!" << endl;
continue;
}
}
if (unSumKM > 15000u)
{
cout << "Out of rang!" << endl;
continue;
}
if (unSumKM < unK)
unSumKM = unK;
strID = chID;
iterCur = mapAOV.find(strID);
if (iterCur == mapAOV.end())
{
mapAOV.insert(make_pair(strID, unSumKM));
}
else
{
iterCur->second += unSumKM;
}
++i;
}
cout << "Query" << endl;
cin >> llRecoder;
i = 0;
while (i < llRecoder)
{
cin >> chID ;
if (chID[17] < '0' || chID[17] > '9')
{
if (chID[17] != 'x')
{
cout << "RecoderID format error!" << endl;
continue;
}
}
strID = chID;
iterCur = mapAOV.begin();
while (iterCur != mapAOV.end())
{
if (iterCur->first == strID)
{
cout << (iterCur->second < unK ? unK : iterCur->second) << endl;
break;
}
iterCur++;
}
if (iterCur == mapAOV.end())
{
cout << "No Info" << endl;
}
++i;
}
return 0;
}
热心网友
时间:2023-11-04 12:27
#include <stdio.h>
#include <string.h>
#define LEN 131313
long hashval[LEN+10000];
char hashstr[LEN+10000][19];
unsigned int hashfun(char raw_key[19])
{
unsigned int key = 0;
char* c = raw_key;
while(*c)
key = key*LEN + *c++;
return key%LEN;
}
int main()
{
int n,t,m;
long val;
char raw_key[19];
unsigned int key;
memset(hashval,0,sizeof(hashval));
memset(hashstr,0,sizeof(hashstr));
scanf("%d%d%*c",&n,&t);
while(n--)
{
scanf("%s%ld%*c",raw_key,&val);
if (val < t)
val = t;
key = hashfun(raw_key);
while(hashstr[key][0]!=0 && strcmp(hashstr[key],raw_key)!=0)
key++;
if(hashstr[key][0]==0)
{
hashval[key] = val;
strcpy(hashstr[key],raw_key);
}
else
hashval[key] += val;
}
scanf("%d%*c",&m);
while(m--)
{
gets(raw_key);
key = hashfun(raw_key);
while(hashstr[key][0]!=0 && strcmp(hashstr[key],raw_key)!=0)
key++;
if(hashstr[key][0]==0)
printf("No Info\n");
else
printf("%d\n",hashval[key]);
}
return 0;
}