2018四川省省赛B.Beyond the Boundry(纯暴力)three

版权声明:本文为博主原创文章,未经博主允许不得转载。

Titles:

    Given  a character string representing the vague name written on the paper, of which the blank has been omitted, you are supposed to output the possible original names of it(which means that after obliterating the blank and some of the characters of the person's name,it turns into the vague name which is given). If multiple names match the vague name, output all of them in the lexicographical order.

    Attention: uppercase letters and lowercase letters are distinctive!

Constraints:

    1 <= T <= 10000

Example

standard input:

3

NaseMitsuki

a

ka

 standard output:

1

Nase Mitsuki

4

Kanbara Akihito

Kuriyama Mirai

Nase Hiroomi

Nase Mitsuki

2

Kanbara Akihito

Kuriyama Mirai

解题思路:

    最开始的时候,自己想写如下这样一个结构体来将是否满足和相应的字符串进行绑定。

struct node
{
	char name[20];
	int right;
}stu[5];

    后来发现自己不会对结构体数组里面的字符串进行赋值,就放弃了这个方法。

进而发现这四个同学名字的字符串可以在复制的时候,就排好字典序,那么在程序执行的过程中,就只需要判断其是否含有相应的上升子序列就可以了。因此改用了bool类型的变量来进行判断。之后就纯暴力(当然还是要注意下,我们赋值输入的字符串是含有空格的,跳过即可)。

代码实现如下:

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;

int main()
{
	char name[5][20] = {"Kanbara Akihito","Kuriyama Mirai","Nase Hiroomi","Nase Mitsuki"};
	char str[20];
	int t,num,ans,j,i;
	scanf("%d",&t);
	while(t--)
	{
		bool f1 = 1,f2 = 1,f3 = 1,f4 = 1;
		int pos = 0,num = 0,ans = 0;
		scanf("%s",str);
		int len = strlen(str);
		for(i = 0;i < len; i++)
		{
			for(j = pos; j < 15; j++)
			{
				if(name[0][j] == ' ')
					continue;
				if(str[i] == name[0][j])
				{
					num++;
					pos = j + 1;
					break;
				}
			}
		}
		if(num >= len)
			ans++;
		else
			f1 = 0;

		num = 0;
		pos = 0;
		for(i = 0;i < len; i++)
		{
			for(j = pos; j < 15; j++)
			{
				if(name[1][j] == ' ')
					continue;
				if(str[i] == name[1][j])
				{
					num++;
					pos = j + 1;
					break;
				}
			}
		}
		if(num >= len)
			ans++;
		else
			f2 = 0;

		num = 0;
		pos = 0;
		for(i = 0;i < len; i++)
		{
			for(j = pos; j < 15; j++)
			{
				if(name[2][j] == ' ')
					continue;
				if(str[i] == name[2][j])
				{
					num++;
					pos = j + 1;
					break;
				}
			}
		}
		if(num >= len)
			ans++;
		else
			f3 = 0;

		num = 0;
		pos = 0;
		for(i = 0;i < len; i++)
		{
			for(j = pos; j < 15; j++)
			{
				if(name[3][j] == ' ')
					continue;
				if(str[i] == name[3][j])
				{
					num++;
					pos = j + 1;
					break;
				}
			}
		}
		if(num >= len)
			ans++;
		else
			f4 = 0;

		printf("%d\n",ans);
		if(f1)
			puts(name[0]);
		if(f2)
			puts(name[1]);
		if(f3)
			puts(name[2]);
		if(f4)
			puts(name[3]);
		}
		return 0;
}

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值