Home > Back-end >  Be divided exactly by 3 subsequence (pass) 9.09
Be divided exactly by 3 subsequence (pass) 9.09

Time:10-05

Source:
 
#include
#include
#include
Char s [50];
int num;//output integers
Int S [50];//string corresponding integer
Int sn;
Int division (int a, int b) {
int count=0;
If (a % b==0) count++;
Return the count.
}
The main () {
The scanf (" % s ", & amp; S);
Int I=0, j, k;
Int the ls;
Ls=strlen (s);
Num=0;
Sn=s - '0';
for(i=0; S [I]; I++) {
For (k=1; S [I] + k; K++) {
If (I + k>=(ls) break;
for(j=0; j<=k; J++) {
If (j + i>=(ls) break;
S=S [I] + [j] I - '0';
Num=num + division (S [I], 3);
}
}
}

Printf (" % d ", num);
}

5 test cases of actual and expected output:
132 3 3
9 0 1
333 7 7
123456 16 23
00 2, 3,

  • Related