Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- using namespace std;
- ifstream fin("control.in");
- ofstream fout("control.out");
- int v[100005];
- int sumcif(int x)
- {
- int s=0;
- while(x)
- {
- s+=x%10;
- x/=10;
- }
- return s;
- }
- int main()
- {
- int n,i,j,cerinta,cifcontrol,lungime,rezultat=0;
- int start=0,s=0,stop=0;
- fin>>cerinta;
- fin>>n>>cifcontrol>>lungime;
- for(i=1; i<=n; i++)
- {
- fin>>v[i];
- }
- if(cerinta==1)
- {
- for(start=1; start<=n; start++)
- {
- s=0;
- for(stop=start; stop<=n; stop++)
- {
- s+=v[stop];
- if(s>9)
- {
- sumcif(v[stop]);
- }
- if(s==cifcontrol && stop-start+1<=lungime)
- {
- rezultat++;
- }
- }
- }
- }
- else if(cerinta==2)
- {
- for(start=1;start<=n;start++)
- {
- s=0;
- for(stop=start;stop<=n;stop++)
- {
- s+=v[stop];
- if(s>9)
- {
- s=s%10+s/10%10;
- }
- if(s==cifcontrol)
- {
- rezultat++;
- }
- }
- }
- }
- fout<<rezultat;
- fin.close();
- fout.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement