Advertisement
Anon2005

puzzle

Sep 29th, 2022
1,101
-1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.81 KB | None | 0 1
  1. #include <fstream>
  2. using namespace std;
  3. ifstream in("puzzle.in");
  4. ofstream out("puzzle.out");
  5. int v[100001],vf[100001];
  6. int nrcif(int n)
  7. {
  8.     int cnt=0;
  9.     while(n)
  10.     {
  11.         n/=10;
  12.         cnt++;
  13.     }
  14.     return cnt;
  15. }
  16. int main()
  17. {
  18.     int n,i;
  19.     in>>n;
  20.     for(i=1; i<=n; i++)
  21.     {
  22.         in>>v[i];
  23.         vf[v[i]]++;
  24.     }
  25.     int x=nrcif(v[1]),nr=1;
  26.     for(i=1; i<x; i++)
  27.         nr=nr*10+1;
  28.     long long rez=0;
  29.     for(i=1; i<=n; i++)
  30.     {
  31.         int ci=v[i],maxcif=0;
  32.         while(ci)
  33.         {
  34.             maxcif=max(maxcif,ci%10);
  35.             ci/=10;
  36.         }
  37.         for(int s=maxcif+1; s<=9; s++)
  38.             if(s*nr-v[i]!=v[i])
  39.                 rez+=vf[s*nr-v[i]];
  40.             else
  41.                 rez+=vf[s*nr-v[i]]-1;
  42.     }
  43.     out<<rez/2;
  44.     return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement