Advertisement
nicuvlad76

Untitled

Mar 11th, 2023
739
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.89 KB | None | 0 0
  1. #include<fstream>
  2. #include<cstring>
  3. using namespace std;
  4. ifstream fin("cifre12.in");
  5. ofstream fout("cifre12.out");
  6. unsigned long long n, N, v, S,P, c;
  7. int s[10]={6, 2, 5, 5, 4, 5, 6, 3, 7 , 6};
  8. int a[10]={1 , 5, 1, 2, 2, 3, 1, 2, 0, 0};///cate cifre mai mari se pot obtine
  9. int b[10]={2, 7, 2, 3, 3, 4, 2, 5, 1, 2 };
  10. int w[25],k;
  11. int main()
  12. {
  13.  fin>> v>> n;
  14.  if(v==1)
  15.  {
  16.       S=0;
  17.      while(n!=0)
  18.      {
  19.         c=n%10;
  20.         S+=s[c];
  21.         n/=10;
  22.      }
  23.      fout<<S;
  24.  }
  25.  else
  26.  {
  27.      N=n;k=0;
  28.      while(N!=0){
  29.         w[++k]=N%10;
  30.         N/=10;
  31.      }
  32.      for(int i=1, j=k;i<j; i++, j--)
  33.         swap(w[i], w[j]);
  34.      S=0;
  35.      for(int i=1;i<=k;i++)
  36.      {
  37.          if(a[w[i]]!=0)
  38.          {
  39.              P=a[w[i]];
  40.              for(int j=i+1;j<=k;j++)
  41.                 P*=b[w[j]];
  42.              S+=P;
  43.          }
  44.      }
  45.      fout<<S;
  46.  }
  47.   return 0;
  48. }
  49.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement