Count words that are the same as the first word of a Vector

0

I would like to know how to do this exercise:

Given a sentence ending with a point in a vector, perform an algorithm that tells us how many words are the same as the first word.

I do not need the code, since we are doing it in pseudocode, but we will do C in nothing.

The fact is that I have read the vector entered by the user, then I have read the first word and I have saved it in a vector "j". Then I read word by word from the vector to compare: if v[i] == j[i] (first word), then what cont = cont +1 .

The problem is that I do not know how to "go picking up" word by word to compare it.

I made this loop:

i = 0;

mientras (i < = 20) & (v[i] != '.') & (v[i] != ' ') hacer

    si (v[i] == j[i]) entonces
       cont = cont +1;
    fsi
    i ++;
fmientras

I do not know if what I've done is fine, but good.

    
asked by Alex Iglesias 29.12.2017 в 19:18
source

1 answer

0

You just have to reason, what does the end of the word indicate? In Western languages we can say that the end of a word is determined by a punctuation mark or a space. You can iterate letter by letter and when you reach one of the following characters , . : ! ? (space) you can get the word and compare it with the first vector j . Then if you start with a letter after this interruption it means that you are in a new word and so on.

    
answered by 02.01.2018 в 14:04