Codeforces Beta Round 99 (Div. 2) 139A - Petr and Book Solution



 Problem Link :  https://codeforces.com/problemset/problem/139/A

Solution in C++:

  1. /// La ilaha illellahu muhammadur rasulullah
  2. ///******Bismillahir-Rahmanir-Rahim******///
  3. /// Abul Hasnat Tonmoy
  4. /// Department of CSE,23rd batch
  5. /// Islamic University,Bangladesh
  6. ///**********ALLAH IS ALMIGHTY************///
  7. #include <bits/stdc++.h>
  8. using namespace std;
  9. int main() {
  10. int n ;
  11. cin >> n ;
  12. int a[9] ;
  13. for ( int i = 1 ; i <= 7 ; i++ ) {
  14. cin >> a[i] ;
  15. }
  16. int sum = 0 , i = 1 ;
  17. while (1) {
  18. sum += a[i] ;
  19. i++ ;
  20. if ( sum >= n ) {
  21. cout << i - 1 << endl ;
  22. break ;
  23. }
  24. if ( i == 8) {
  25. i = 1 ;
  26. }
  27. }
  28. return 0;
  29. }

No comments

Most View Post

Recent post

RESTful APIs with CRUD Operations in Laravel 12| (2025)

  RESTful APIs serve as the foundation of modern web development. They follow a set of rules called Representational State Transfer (REST) t...

Powered by Blogger.