Last active
March 27, 2019 09:40
-
-
Save invatainfo/124406bc2e330fd66e77ffb807040812 to your computer and use it in GitHub Desktop.
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
#include <iostream> | |
#include <string.h> | |
using namespace std; | |
#define NUMAR_CUVINTE 4 | |
/** | |
* Functie ce verifica daca un cuvant | |
* p este prescurtat - pe ultima pozitie | |
* este '.'. Intoarce 1 daca este prescurtat | |
* si 0 altfel. | |
*/ | |
int verifica_daca_prescurtat(char *p) { | |
return p[strlen(p) - 1] == '.'; | |
} | |
int main() { | |
char *cuvinte[4] = {"COLEGIUL", "LICEUL", "NATIONAL", "TEORETIC"}; | |
char delim[] = " \n", *p; | |
char text[51], text_afisat[100000]; | |
int i; | |
cin.getline(text, 51); | |
p = strtok(text, delim); | |
text_afisat[0] = '\0'; | |
// iau cuvant cu cuvant din text | |
while (p != NULL) { | |
// daca este prescurtat | |
if (verifica_daca_prescurtat(p)) { | |
// scap de '.' de la sfarsit | |
// pentru a putea compara | |
p[strlen(p) - 1] = '\0'; | |
// iau fiecare cuvant din cele 4 ce pot fi prescurtate | |
// si verific daca p este o prescurtare a unuia dintre | |
// ele | |
for (i = 0; i < NUMAR_CUVINTE; i++) { | |
// daca p e prescurtate a cuvantului cuvinte[i] | |
if (strstr(cuvinte[i], p) == cuvinte[i]) { | |
// fac p egal cu cuvinte[i] si ies | |
// din for | |
p = cuvinte[i]; | |
break; | |
} | |
} | |
} | |
// pun p in text_afisat | |
if (text_afisat[0] == '\0') { | |
strcpy(text_afisat, p); | |
} else { | |
strcat(text_afisat, " "); | |
strcat(text_afisat, p); | |
} | |
// iau urmatorul cuvant | |
p = strtok(NULL, delim); | |
} | |
// afisez cuvantul | |
cout << text_afisat << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment