任何人都可以指导如何匹配两个字符串是否已经输入 [英] Can anyone please guide how to match two string whether previous already inputted

查看:88
本文介绍了任何人都可以指导如何匹配两个字符串是否已经输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给定n,即作为输入的字符串数。对于每个输入,使用必须打印是或否,无论当前字符串是否已经存在。



输入:

5

极客

你好

很棒

极客

你好

输出:















我的尝试:



Given n, which is the number of strings taken as input. For each input use have to print "YES" or "NO" whether the current string is already present or not.

Input:
5
Geeks
Hello
Great
Geeks
Hello
Output:

No
No
No
Yes
Yes

What I have tried:

bool isSubSequence(char str1[], char str2[], int m, int n)
{
    // Base Cases
    if (m == 0) return true;
    if (n == 0) return false;
 
    // If last characters of two strings are matching
    if (str1[m-1] == str2[n-1])
        return isSubSequence(str1, str2, m-1, n-1);
 
    // If last characters are not matching
    return isSubSequence(str1, str2, m, n-1);
}

推荐答案

想想你的代码应该做什么:查找每个新字符串是否已经在我的数组中?



=>所以你需要每次遍历整个数组。

a)使用for循环

b)当发现你已经完成

c)循环所有条目后你知道你还没找到它。

奖金:(仅限于添加)



您可以使用一些 C ++教程学习基础知识。



自己开发代码和伪代码以学习编程。总是使用动词和对象。



第一个可以是:输入数字输入
think about what your code should do: "Look up every new string whether it is already in my array?"

=> so you need to loop every time through the complete array.
a) use a for loop
b) when found you are done
c) after looping all entry you know that you havent found it.
bonus: (only than add it)

You can use some C++ tutorial to learn the basics.

Develop your code and pseudo code yourself to learn programming. Use always a verb and objects.

The first can be: "Ask numbers for input"


我是编程的初学者,你能不能给我提供伪代码
I beginner to programming, can you please provide pseudocode to me


这篇关于任何人都可以指导如何匹配两个字符串是否已经输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆