[2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest][Codeforces 883 E]Field of Wonders
[2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest][Codeforces 883 G]Orientation of Edges

[2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest][Codeforces 883 F]Lost in Transliteration

Zarxdy34 posted @ 2017年10月23日 09:04 in Codeforces with tags 字符串 , 402 阅读

    题意:给出n个字符串,字符串中"oo"与"u"等价,"kh"与"h"等价("kkh"也与"h"等价),求不同字符串的数目。

    题解:把所有"u"变成"oo"(不能反过来,否则"uo"和"ou"会判断错误),把"h"前面的"k"全部删去,然后比较有多少个不同的字符串即可。

 

#include <bits/stdc++.h>
using namespace std;
const int maxn=410;

void Change(char *s)
{
	int n=strlen(s);
	for (int i=0;i<n;i++)
	{
		if (s[i]=='u')
		{
			n++;
			for (int j=n-1;j>i+1;j--) s[j]=s[j-1];
			s[i]=s[i+1]='o';
		}
		if (s[i]=='h')
		{
			while (i>0 && s[i-1]=='k')
			{
				i--;
				n--;
				for (int j=i;j<n;j++) s[j]=s[j+1];
			}
		}
	}
	s[n]='\0';
}

char s[maxn][50];
int n,ans;

int main()
{
	scanf("%d",&n);
	for (int i=0;i<n;i++)
	{
		scanf("%s",s[i]);
		Change(s[i]);
	}
	for (int i=0;i<n;i++)
	for (int j=i+1;j<n;j++)
		if (strcmp(s[i],s[j])>0) swap(s[i],s[j]);
	for (int i=1;i<n;i++) if (strcmp(s[i],s[i-1])) ans++;
	printf("%d\n",ans+1);
	return 0;
}

登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter