fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. vector<int> arr={1,2,3,4,5};
  6. int n=arr.size();
  7. int k=4;
  8. //print all subarrays
  9. for(int i=0;i<5;i++){
  10. int sum=0;
  11. for(int j=4;j>=i;j--){
  12. cout<<arr[j]<<" ";
  13. sum+=arr[j];
  14. }
  15. if(sum%k==(n-i)+1){
  16. cout<<" -- good";
  17. }else{
  18. cout<<" -- bad";
  19. }
  20. cout<<endl;
  21. }
  22. return 0;
  23. }
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
1 
1 2 
1 2 3 
1 2 3 4 
1 2 3 4 5 
2 
2 3 
2 3 4 
2 3 4 5 
3 
3 4 
3 4 5 
4 
4 5 
5