fork download
  1. #include <iostream>
  2. #include <cstring>
  3. using namespace std;
  4.  
  5. int main() {
  6. bool existaInvitati = false;
  7. char listaInvitati[250], separatori[3] = "; ", x[250], *prenume, *nume;
  8. cin.getline(listaInvitati, 250);
  9. cin >> x;
  10. //cout << listaInvitati << endl;
  11. //cout << x << endl;
  12. prenume = strtok(listaInvitati, separatori);
  13. while (prenume != NULL) {
  14. nume = strtok(NULL, separatori);
  15. char aux[250];
  16. strcpy(aux, prenume);
  17. //cout << p << ' ' << x << endl;
  18. if (!strcmp(aux, x)) {
  19. existaInvitati = true;
  20. cout << nume << ' ';
  21. }
  22. prenume = strtok(NULL, separatori);
  23. }
  24. if (!existaInvitati) {
  25. cout << "NU";
  26. }
  27. return 0;
  28. }
Success #stdin #stdout 0.01s 5520KB
stdin
DAN MARIS; DANILA PREPELEAC; DAN POPA; EDANA DAN;
DAN
stdout
MARIS POPA