U E D R , A S I H C RSS

[Lovely]boy^_^/USACO/Greedy Gift Givers

  • 역시 영어가 부족해 ㅠ.ㅠ 해석을 똑바로 했으면 금방 했을텐데..;;
  • 혹시 map에 삽입할때 정렬 안되게 하는 법 없나요?;; 아무리 해도 방법이 안 떠올라서 따로 string 벡터를 만들어서 저장했는데;; 너무 더러워져서;;


~cpp 
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>

using namespace std;

map<string,int> List;
vector<string> ManList;

int max_num = 0;
ifstream fin("gift1.in");
ofstream fout("gift1.out");

void Free();
void InputData();
void OutputData();

int main()
{
	InputData();
	OutputData();
	fout.close();
	fin.close();
	return 0;
}

void InputData()
{
	fin >> max_num;

	string name;
	for(int k = 0 ; k < max_num ; ++k)
	{
		fin >> name;	
		List[name] = 0;
		ManList.push_back(name);
	}

	string tempname;
	int tempmoney;
	int numto;
	for(int k = 0 ; k < max_num ; ++k)
	{
		fin >> tempname;
		fin >> tempmoney;
		fin >> numto;

		List[tempname] -= tempmoney;

		string tempname2;
		int dist;
		if(numto)
			dist = tempmoney / numto;
		for(int j = 0 ; j < numto ; ++j )
		{
			fin >> tempname2;
			List[tempname2] += dist;
		}

		if(tempmoney - dist * numto) 
		{
			List[tempname] += (tempmoney - dist * numto);
		}
	}
}

void OutputData()
{
	for(int i = 0 ; i < max_num ; ++i)
		fout << ManList[i] << " " << List[ManList[i]] << endl;
}
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:28:37
Processing time 0.0215 sec