zoukankan      html  css  js  c++  java
  • POJ1035(字符串)

    大意:判断一个字符串能否由字典中的字符串替换,删除或插入一个字符得到。

    分析:水题

    代码

    #include <iostream>
    #include <string>
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    using namespace std;
    char dic[10005][17],ch[55][17];
    int dic1[10005];
    void rep(char s[])
    {
    	char s1[17];
    	for (int i = 0; dic[i][0] != '#'; i++)
    	{
    		int num = 0;
    		if (strlen(s) == strlen(dic[i]))
    		{
    			for (int j = 0; j < strlen(s); j++)
    			{
    				if (s[j] != dic[i][j])
    					num++;
    			}
    			if (num == 1)
    			{
    				dic1[i] = 1;
    
    			}
    		}
    		if (strlen(s) + 1 == strlen(dic[i]))
    		{
    			int n = 0, m = 0;
    			while(m <strlen(dic[i]))
    			{
    				if (s[n] == dic[i][m])
    				{
    					n++; m++;
    				}
    				else
    				{
    					m++;
    				}
    				if (m - n > 1)
    					break;
    			}
    			if (m - n == 1)
    				dic1[i] = 1;
    		}
    		if(strlen(s) - 1 == strlen(dic[i]))
    		{
    			int n = 0, m = 0;
    			while (m < strlen(s))
    			{
    				if (s[m] == dic[i][n])
    				{
    					n++; m++;
    				}
    				else
    				{
    					m++;
    				}
    				if (m - n > 1)
    					break;
    			}
    			if (m - n == 1)
    				dic1[i] = 1;
    		}
    	}
    }
    int main()
    {
    	//freopen("C:\in.txt", "r", stdin);
    	for (int i = 0;; i++)
    	{
    		scanf("%s", dic[i]);
    		if (dic[i][0]=='#')
    			break;
    	}
    	for (int i = 0;; i++)
    	{
    		scanf("%s", ch[i]);
    		if (ch[i][0] == '#')
    			break;
    	}
    	for (int i = 0; ch[i][0] != '#'; i++)
    	{
    		memset(dic1, 0, sizeof(dic1));
    		int flag = 0;
    		for (int j = 0; dic[j][0] != '#'; j++)
    		{
    			if (strcmp(ch[i],dic[j])==0)
    			{
    				flag = 1;
    				break;
    			}
    		}
    		if (flag == 1)
    			printf("%s is correct
    ", ch[i]); 
    		else
    		{
    			printf("%s:", ch[i]);
    			rep(ch[i]);
    			for (int i = 0; dic[i][0] != '#'; i++)
    			{
    				if (dic1[i] == 1)
    					printf(" %s", dic[i]);
    			}
    			printf("
    ");
    		}
    	}
    	return 0;
    }


  • 相关阅读:
    ES6:Iterator遍历器
    前端:对BFC的理解
    前端:性能优化之防抖与节流
    ES6新增数据类型Symbol
    ajax和fetch、aixos的区别
    我对js数据类型的理解和深浅(copy)的应用场景
    egg的基本使用
    前端:css3的过渡与动画的基础知识
    Java基础篇之类
    JAVA基础篇之Scanner
  • 原文地址:https://www.cnblogs.com/nickqiao/p/7583394.html
Copyright © 2011-2022 走看看