A Simple Job
#include<stdio.h>
#include<map>
#include<string>
#include<iostream>
using namespace std;
typedef pair<int, int> Pii;
map<string, int> m1;
map<int, string> m3;
map<Pii, int> m2;
bool operator<(const Pii & a, const Pii &b)
{
if (a.first != b.first)
return a.first < b.first;
else
return a.second < b.second;
}
int wordCount;
int arr[510];
int acount;
Pii ansWord;
int maxTime;
int main()
{
string s;
m1.clear();
m2.clear();
m3.clear();
wordCount = 1;
arr[0] = 0;
acount = 1;
m1[","] = 0;
maxTime = 0;
while (getline(cin, s))
{
do
{
if (s == "####")
{
if (!m2.empty())
{
auto sdfsf = (*m2.begin());
ansWord = sdfsf.first;
maxTime = sdfsf.second;
for (auto ppp : m2)
{
if (maxTime < ppp.second)
{
ansWord = ppp.first;
maxTime = ppp.second;
}
else if (maxTime == ppp.second)
{
if (m3[ppp.first.first] < m3[ansWord.first])
{
ansWord = ppp.first;
maxTime = ppp.second;
}
else if (m3[ppp.first.first] == m3[ansWord.first] && m3[ppp.first.second] < m3[ansWord.second])
{
ansWord = ppp.first;
maxTime = ppp.second;
}
}
}
printf("%s %s:%d\n", m3[ansWord.first].c_str(), m3[ansWord.second].c_str(), maxTime);
//printf("%d test\n", m2[{4, 3}]);
}
m1.clear();
m2.clear();
m3.clear();
wordCount = 1;
arr[0] = 0;
acount = 1;
m1[","] = 0;
maxTime = 0;
continue;
}
acount = 1;
string word;
for (int i = 0; i < s.size(); i++)
{
if (s[i] == ',' || s[i] == '.')
{
if (!word.empty())
{
if (m1.count(word) == 0)
{
m1[word] = wordCount;
m3[wordCount] = word;
wordCount++;
}
arr[acount] = m1[word];
acount++;
word.clear();
}
arr[acount] = 0;
acount++;
}
else if (s[i] != ' ')
word += s[i];
else if (!word.empty())
{
if (m1.count(word) == 0)
{
m1[word] = wordCount;
m3[wordCount] = word;
wordCount++;
}
arr[acount] = m1[word];
acount++;
word.clear();
}
}
if (!word.empty())
{
if (m1.count(word) == 0)
{
m1[word] = wordCount;
m3[wordCount] = word;
wordCount++;
}
arr[acount] = m1[word];
acount++;
word.clear();
}
/*for (int i = 0; i < acount; i++)
printf("%d ", arr[i]);
printf("\n");*/
for (int i = 1; i < acount; i++)
{
if (arr[i - 1] != 0 && arr[i] != 0)
{
Pii pii;
pii.first = arr[i - 1];
pii.second = arr[i];
if (m2.count(pii))
{
m2[pii]++;
}
else
{
m2[pii] = 1;
}
}
}
} while (getline(cin, s));
}
}