1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
// This code is GPL, blah blah
//
// Writen for TheManaWorld by Chuck Miller, A.K.A. Kage
#include <iostream>
#include <string>
using namespace std;
int itemID;
int itemCount(string itemData)
{
int counter = 0;
int pointer = 0;
do
{
int ending = itemData.find(',', pointer + 1);
if (ending == string::npos)
ending = itemData.size();
if (counter == 1 && atoi(itemData.substr(pointer, ending - pointer).c_str()) != itemID)
return 0;
if (counter == 2)
return atoi(itemData.substr(pointer, ending - pointer).c_str());
counter++;
} while ((pointer = itemData.find(',',pointer) + 1) != string::npos + 1);
return 0;
}
int parseItemData(string &items)
{
int counter = 0;
int pointer = 0;
int total = 0;
do
{
int ending = items.find(' ', pointer + 1);
if (ending == string::npos)
ending = items.size();
total += itemCount(items.substr(pointer, ending - pointer));
counter++;
} while ((pointer = items.find(' ',pointer) + 1) != string::npos + 1);
return total;
}
void parseLine(string &line)
{
int counter = 0;
int pointer = 0;
string AccountId, Name, Items;
do
{
if (counter == 1 || counter == 2 || counter == 15)
{
int ending = line.find('\t', pointer + 1);
if (ending == string::npos)
ending = line.size();
switch (counter)
{
case 1:
AccountId = line.substr(pointer,ending - pointer);
break;
case 2:
Name = line.substr(pointer, ending - pointer);
break;
case 15:
Items = line.substr(pointer, ending - pointer);
}
}
counter++;
} while ((pointer = line.find('\t',pointer) + 1) != string::npos + 1 && counter < 16);
if ((counter = parseItemData(Items)) > 0)
cout << "Account = " << AccountId << "; Name = \"" << Name << "\"; Count = " << counter << "\n";
}
void parseInput()
{
string input;
while (getline(cin, input))
{
parseLine(input);
}
}
int main(int argc,char *argv[])
{
if(argc < 2)
{
printf("Usage: %s <item ID>\n", argv[0]);
printf("e.g., %s 701\n", argv[0]);
printf("Will return all users who own that item\n");
exit(0);
}
itemID = atoi(argv[1]);
parseInput();
return 0;
}
|