前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >2018四川省大学程序设计竞赛(ACM)B: Beyond the Boundry ----------C语言——菜鸟级

2018四川省大学程序设计竞赛(ACM)B: Beyond the Boundry ----------C语言——菜鸟级

作者头像
Fivecc
发布2022-11-21 15:04:16
1740
发布2022-11-21 15:04:16
举报
文章被收录于专栏:前端ACE

B: Beyond the Boundry Time Limit: 1000 MS Memory Limit: 1048576 KB Total Submit: 98 Accepted: 51 Page View: 407 Submit Status Clarify

Description There are four students, Kanbara Akihito, Kuriyama Mirai, Nase Hiroomi and Nase Mitsuki, studying in the senior middle school. They all took part in an exam the other day. Now it`s your turn to give papers back to them. However, the names were written so vaguely that you barely recognize any letters of their names.

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!

Input The first line contains a integer T T representing the number of test cases. In each test case, there is a non-empty string s s in one line. It is guaranteed that s contains only English letters and is a subsequence of at least one student’s name. 1≤T≤10000 1≤T≤10000

Output For each test case, output an integer n in the first line representing the number of students satisfying that s is a subsequence of their names. There are n lines following (in lexicographical order). Each of them contains a name which might be the original name of the vague name.

Sample Input

Raw

3 NaseMitsuki a Ka

Sample Output

Raw

1 Nase Mitsuki 4 Kanbara Akihito Kuriyama Mirai Nase Hiroomi Nase Mitsuki 2 Kanbara Akihito Kuriyama Mirai

思路: 分别判断4个母串 中 是否存在 递增子序列 与 匹配串相同

AC代码

代码语言:javascript
复制
#include <stdio.h>
#include <string.h>
int main()
{
    int T,i,j,k,now,ans,len;char str[4][20]={"Kanbara Akihito","Kuriyama Mirai","Nase Hiroomi","Nase Mitsuki"};
    int s[4][260][5];char ps[20];int res[5];
    memset(s,0,sizeof(s));
    for(i=0;i<4;i++)
     {  len=strlen(str[i]);
      for(j=0;j<len;j++)
       { k=0;
        while(s[i][str[i][j]][k])k++;//判断是否前面出现过该字符 
          s[i][str[i][j]][k]=j+1;//位置从1开始 所以 j+1; 
		//在第i个字符串中第 j 个字符在该字符串的位置 
		 //0 1 2 3 4 5 6   j
		// K a n b a r a 
		// s[i][str[i][j]][k]=j+1;
		// s[0][str[0][6]][3]=j+1;
		// s[0][97][3]=7;
		// {s[0][97][2]=5;
		// s[0][97][3]=2;}
       }
	 }
    scanf("%d\n",&T);
    while(T--)
    {  memset(res,0,sizeof(res));ans=0;
        gets(ps);
        len=strlen(ps);
        for(i=0;i<4;i++)
        {   now=0;
            for(j=0;j<len;j++)
            {  k=0;
                while(now>=s[i][ps[j]][k]&&k<4)k++;//判断是否有匹配但前字符且
                if(k==4)break;  //未匹配 成功     // 在母串中位置比上一个匹配字符位置大 
                now=s[i][ps[j]][k];//更新当前匹配 
            }
            if(j==len)res[i]=i+1,ans++;//符合条件 存入结果数组 
        }
        printf("%d\n",ans);
        for(i=0;i<5;i++)
        if(res[i])printf("%s\n",str[res[i]-1]);
    }
    return 0;
}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2018-06-05,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档