Advertisement
Five_NT

probl 6

Dec 22nd, 2015
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.70 KB | None | 0 0
  1.  
  2.  
  3. bool rimes(char* first_word, char* second_word, int n)
  4. {
  5.  
  6. //    int l1 = strlen(first_word), l2 = strlen(second_word);
  7.     if((int)strlen(first_word) < n) return false;
  8.     if((int)strlen(second_word) < n) return false;
  9.  
  10.    // cout << first_word+(strlen(first_word)-n) << endl << second_word+(strlen(second_word)-n);
  11.     if(strcmp(first_word+(strlen(first_word)-n), second_word+(strlen(second_word)-n)) == 0)
  12.         return true;
  13.     else
  14.         return false;
  15.  
  16. }
  17.  
  18. void problema6(const char *input_file, const char *output_file)
  19. {
  20.     ifstream fin(input_file);
  21.     ofstream fout(output_file);
  22.     char s[4][101], v[4][100], elem[100];
  23.     char chr[] = ".,?! ";
  24.     unsigned int n;
  25.     fin >> n;
  26.     fin.get();
  27.     for(unsigned int i = 0; i<4; i++)
  28.     {
  29.         fin.getline(s[i], 101);
  30.         char *p;
  31.         p = strtok(s[i], chr);
  32.  
  33.         while( p != NULL )
  34.         {
  35.             strcpy(elem, p);
  36.             p = strtok(NULL, chr);
  37.         }
  38.         strcpy(v[i], elem);
  39.  
  40.         //fin.get();
  41.     }
  42.  
  43.     if(rimes(v[0], v[1], n) == true && rimes(v[2], v[3], n) == true && rimes(v[0], v[2], n) == false && rimes(v[0], v[3], n) == false)
  44.         fout << "A\n";
  45.     else if(rimes(v[0], v[2], n) == true && rimes(v[1], v[3], n) == true && rimes(v[0], v[1], n) == false && rimes(v[0], v[3], n) == false)
  46.         fout << "B\n";
  47.     else if(rimes(v[0], v[3], n) == true && rimes(v[1], v[2], n) == true && rimes(v[0], v[1], n) == false && rimes(v[0], v[2], n) == false)
  48.         fout << "C\n";
  49.     else if(rimes(v[0], v[1], n) == true && rimes(v[0], v[2], n) == true && rimes(v[0], v[3], n) == true)
  50.         fout << "D\n";
  51.     else fout << "E\n";
  52.  
  53.  
  54.     fin.close();
  55.     fout.close();
  56.  
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement