Advertisement
Guest User

Frati

a guest
Jan 23rd, 2020
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.05 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. using namespace std;
  5.  
  6. ifstream f("date.in");
  7.  
  8. int x[10000];
  9.  
  10. bool frate(int a,int b) {
  11.     //cout << a << " " << b << endl;
  12.     if (a == b) return false;
  13.     else {
  14.         int fra[10] = { 0 }, frb[10] = { 0 };
  15.         while (a) {
  16.             fra[a % 10]++;
  17.             a /= 10;
  18.         }
  19.         while (b) {
  20.             frb[b % 10]++;
  21.             b /= 10;
  22.         }
  23.         int k = 0;
  24.         for (int i = 0; i <= 9; i++)
  25.         {
  26.             if (fra[i] != 0 and frb[i] != 0)
  27.                 k++;
  28.             if (k == 2) return true;
  29.         }
  30.         return false;
  31.     }
  32. }
  33. int smax, lgmax;
  34. int main() {
  35.     int n;
  36.     f >> n;
  37.     for (int i = 1; i <= n; i++) {
  38.         f >> x[i];
  39.     }
  40.     int start = -1,k=0;
  41.     for (int i = 1; i <= n; i++) {
  42.         bool ok = false;
  43.         for (int j = 1; j <= n; j++) {
  44.             if (i != j) {
  45.                 if (frate(x[i], x[j])) {
  46.                     ok = true; break;
  47.                 }
  48.             }
  49.         }
  50.         if (ok == false) {
  51.             if (start == -1)
  52.                 start = i, k = 1;
  53.             else
  54.                 k++;
  55.         }
  56.         else {
  57.             if (start != -1)
  58.             {
  59.                 if (k > lgmax)
  60.                     lgmax = k, smax = start;
  61.                 k = 0,start =-1;
  62.             }
  63.         }
  64.     }
  65.     cout << smax << " " << lgmax;
  66.  
  67.     return 0;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement