Codeforces C. Pattern 412 解决问题的方法

这个问题是比较暴力的法律主体。

主要是检查每一个是否没有使用足够的?。假设优先使用其他的无论是什么字母,假设你一定不能使用?。

找一个有能力并给予所有的字符串匹配字符串,而且采用的最小?号码。

原标题连接:http://codeforces.com/problemset/problem/412/C

#include <stdio.h>
#include <vector>
#include <string>
#include <iostream>
using namespace std;

int main()
{
	int N;
	scanf("%d", &N);
	vector<string> vst(N);
	for (int i = 0; i < N; i++)
	{
		cin>>vst[i];
	}
	string ans;
	for (int j = 0; j < (int)vst[0].size(); j++)
	{
		bool allX = true;
		char x = vst[0][j];
		for (int i = 1; i < (int)vst.size(); i++)
		{
			if (x == '?')
			{
				x = vst[i][j];
			}
			else if (vst[i][j] != '?' && vst[i][j] != x)
			{
				allX = false;
				x = '?';
				break;
			}
		}
		if (allX && x == '?') ans.push_back('x');//全是?号
		//else if (allX && x != '?') ans.push_back(x);//仅仅有一个不是?号
		else ans.push_back(x);//超过一个不是?号,和上面情况合并了
	}
	cout<<ans;
	return 0;
}


版权声明:笔者靖心脏。景空间地址:http://blog.csdn.net/kenden23/,只有经过作者同意转载。

posted on 2015-10-23 18:18  gcczhongduan  阅读(127)  评论(0编辑  收藏  举报