SSLOJ·WING【模拟】

SSLOJ 1503 WING

    • Description--
    • Input--
    • Output--
    • Sample Input--
    • Sample Output--
    • 解题思路--
    • 代码--

Description–

SSLOJ·WING【模拟】_第1张图片


Input–

在这里插入图片描述

Output–

SSLOJ·WING【模拟】_第2张图片


Sample Input–

5 5
1 WINGG
0 WINGG
1 WINGG
0 GGGGG
1 WIGGG

Sample Output–

-1
1
2

解题思路–

要快读快输


代码–

#include 
#include 
#include 

using namespace std;

int n, c, m, f, ans, d[15][5];
string ss;

int sz(char x)
{
	if (x == 'W') return 1;
	if (x == 'I') return 2;
	if (x == 'N') return 3;
	if (x == 'G') return 4;
}

int read()
{
	int s = 0;
	char c = getchar();
	while (c < '0' || c > '9') c = getchar();
	while (c >= '0' && c <= '9')
	{
		s = s * 10 + (c - '0');
		c = getchar();
	}
	return s;
}

void write(int s)
{
	if (s == 0) return ;
	write(s / 10);
	putchar(s % 10 + '0');
}

void add()
{
	f++; //第f次加入
	for (int i = 0; i < n; ++i)
	{
		int xx = sz(ss[i]);
		d[i][xx] = min(d[i][xx], f); //最早出现的次数
	}
}

void edd()
{
	ans = 0;
	for (int i = 0; i < n; ++i)
	{
		int xx = sz(ss[i]);
		ans = max(ans, d[i][xx]);
		if (ans == d[0][0]) //未出现
		{
			putchar('-');
			putchar('1');
			putchar(10);
			return ;
		}
	}
	write(ans);
	putchar(10);
}

int main()
{
	memset(d, 0x7f, sizeof(d)); //初始化
    n = read(), c = read();
    for (int i = 1; i <= c; ++i)
    {
    	m = read();
    	cin >> ss;
    	if (!m) add(); //加入
    	else edd(); //查询
    }
	
	return 0;
} 

你可能感兴趣的:(模拟)