Facebook
From Gianluca Tarantino, 4 Years ago, written in C++.
Embed
Download Paste or View Raw
Hits: 234
  1. #include "iostream"
  2. #include "fstream"
  3. #include "string"
  4. #include "algorithm"
  5. //#include "cmath"
  6.  
  7. using namespace std;
  8.  
  9. int ciSta(char el, char arr[]) {
  10.         int len = sizeof(arr)/sizeof(arr[0]);
  11.         for (int j=0;j<len;j++) {
  12.                 if (arr[j]==el) return j;
  13.         }
  14.         return -1;
  15. }
  16.  
  17. int main() {
  18.         ifstream in; in.open("input.txt");
  19.         ofstream out; out.open("output.txt");
  20.         int T, D, countl;
  21.         in >> T >> D;
  22.         string parole[T], parole2[T];
  23.         char lettere[T][26];
  24.         for (int j=0;j<T;j++) {
  25.                 in >> parole[j];
  26.         }
  27.         for (int j=0;j<T;j++) {
  28.                 parole2[j] = "";
  29.         }
  30.         for (int i=0;i<T;i++) {
  31.                 countl = 0;
  32.                 string str = parole[i];
  33.                 for (int k;k<str.size();k++) {
  34.                         if (ciSta(str[k],lettere[i])>=0) {
  35.                                 parole2[i] = parole2[i]+to_string(ciSta(str[k],lettere[i]));
  36.                         }
  37.                         else {
  38.                                 lettere[i][countl] = str[k]; countl++;
  39.                                 parole2[i] = parole2[i]+to_string(ciSta(str[k],lettere[i]));   
  40.                         }
  41.                 }
  42.         }
  43.         int dimensioneParole = sizeof(parole2) / sizeof(parole2[0]);
  44.         int max = -1;
  45.         for (int i=0;i<T;i++) {
  46.                 if (count(parole2, parole2+dimensioneParole, parole2[i])>max) {
  47.                         max = count(parole2, parole2+dimensioneParole, parole2[i]);
  48.                 }
  49.         }
  50.         out << max;
  51. }
  52.