Created
November 22, 2023 08:35
-
-
Save juanfal/18f73befad217775eb2a52e9cd40dd72 to your computer and use it in GitHub Desktop.
list of non repeated words
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// readwords.cpp | |
// juanfc 2020-12-14 | |
// A simple case of word reading and simply adding | |
// non-repeated ones to a list, a simple array | |
// of strings | |
// | |
#include <iostream> | |
#include <array> | |
using namespace std; | |
const int N = 100; | |
typedef array<string,N> TWords; | |
void add(TWords& l, string w); | |
int main() | |
{ | |
string w; // w.lenght() -> 0 | |
TWords listOfWords; | |
while (cin >> w and w != "end") | |
add(listOfWords, w); | |
return 0; | |
} | |
void add(TWords& l, string w) | |
{ | |
// we suppose space enough in our list | |
int i = 0; | |
while ( l[i] != "" and w != l[i] ) | |
++i; | |
if (l[i] == "") // not found | |
l[i] = w; // add it the last | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment