Skip to content

Instantly share code, notes, and snippets.

@juanfal
Created November 22, 2023 08:35
Show Gist options
  • Save juanfal/18f73befad217775eb2a52e9cd40dd72 to your computer and use it in GitHub Desktop.
Save juanfal/18f73befad217775eb2a52e9cd40dd72 to your computer and use it in GitHub Desktop.
list of non repeated words
// 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