水题 A Simple Job


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));




	}



}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值