Advertisement
Nita_Cristian

Problema 2 - control

Jan 27th, 2019
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.31 KB | None | 0 0
  1. #include <fstream>
  2. using namespace std;
  3. ifstream fin("control.in");
  4. ofstream fout("control.out");
  5. int v[100005];
  6. int sumcif(int x)
  7. {
  8.     int s=0;
  9.     while(x)
  10.     {
  11.         s+=x%10;
  12.         x/=10;
  13.     }
  14.     return s;
  15. }
  16. int main()
  17. {
  18.     int n,i,j,cerinta,cifcontrol,lungime,rezultat=0;
  19.     int start=0,s=0,stop=0;
  20.     fin>>cerinta;
  21.     fin>>n>>cifcontrol>>lungime;
  22.     for(i=1; i<=n; i++)
  23.     {
  24.         fin>>v[i];
  25.     }
  26.     if(cerinta==1)
  27.     {
  28.         for(start=1; start<=n; start++)
  29.         {
  30.             s=0;
  31.             for(stop=start; stop<=n; stop++)
  32.             {
  33.                 s+=v[stop];
  34.                 if(s>9)
  35.                 {
  36.                     sumcif(v[stop]);
  37.                 }
  38.                 if(s==cifcontrol && stop-start+1<=lungime)
  39.                 {
  40.                     rezultat++;
  41.                 }
  42.             }
  43.         }
  44.     }
  45.     else if(cerinta==2)
  46.     {
  47.         for(start=1;start<=n;start++)
  48.     {
  49.         s=0;
  50.         for(stop=start;stop<=n;stop++)
  51.         {
  52.             s+=v[stop];
  53.             if(s>9)
  54.             {
  55.                 s=s%10+s/10%10;
  56.             }
  57.             if(s==cifcontrol)
  58.             {
  59.                 rezultat++;
  60.             }
  61.         }
  62.     }
  63.     }
  64.     fout<<rezultat;
  65.     fin.close();
  66.     fout.close();
  67.     return 0;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement