UVa-1994 Crossword Answers

#include <cstdio>
#include <vector>
#include <iostream>
#include <deque>
#include <string>
#include <algorithm>
#include <numeric>
#include <utility>
#include <vector>
#include <iterator>
#include <map>
using namespace std;
void dequeout(deque<pair<char, int>> &s, vector<pair<int, string>>&ans)
{
	string temp;
	if (!s.empty())
	{
		for (auto it = s.begin(); it < s.end(); it++)
		{
			temp += it->first;
		}
		ans.push_back({ s.begin()->second,"." + temp });

	}
	s.clear();
}
void out(vector<pair<int, string>>&ans)
{
	sort(ans.begin(), ans.end(), [](pair<int, string>a, pair<int, string>b) {return a.first< b.first; });
	for (auto& i : ans)
	{
		printf("%3d", i.first);
		cout << i.second << endl;
	}
}
int main()
{
	int r,c;
	int puzzles=1;
	while (cin>>r>>c&&r!=0)
	{
		map<string, int> y;
		map<string, int>::mapped_type x;
		vector<vector<pair<char,int>>>maps;
		vector < pair<char, int>>line;
		vector < pair<int, string>>ans;
		char temp;
		
		for (size_t i = 0; i < r; i++)
		{
			for (size_t j = 0; j < c; j++)
			{
				cin >> temp;
				line.push_back({ temp,0});
			}
			maps.push_back(line);
			line.clear();
		}
		if(puzzles!=1)
			cout << endl;
		cout << "puzzle #" << puzzles++<<":"<<endl;
		cout << "Across" << endl;
		deque<pair<char, int>> check_Across;
		int count = 1;
		string nam;
		for (int i = 0; i < r; i++)
		{
			for (int j = 0; j < c; j++)
			{
				if (maps[i][j].first != '*')
				{
					bool is_start = false;
					if (j - 1 >= 0)
					{
						if (i - 1 >= 0)
						{
							if (maps[i - 1][j].first == '*'|| maps[i][j - 1].first == '*')
								is_start = true;
						}
						else
							is_start = true;
					}	
					else
						is_start = true;
					if (is_start)
					{
						maps[i][j].second = count;
						count++;
					}	
					check_Across.push_back(maps[i][j]);
				}
				else
					dequeout(check_Across,ans);
			}
			dequeout(check_Across,ans);
		}
		out(ans);
		cout << "Down" << endl;
		deque<pair<char, int>> check_Down;
		ans.clear();
			for (int j = 0; j < c; j++)
			{
				for (int i = 0; i < r; i++)
				{
					if (maps[i][j].first != '*')
						check_Down.push_back(maps[i][j]);
					else
						dequeout(check_Down,ans);
				}
				dequeout(check_Down,ans);
			}
		out(ans);
	
	}

}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章