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

Codeforces Round 971 (Div. 4) 2009C. The Legend of Freya the Frog Solution

  Problem Link    https://codeforces.com/contest/2009/problem/C S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. h &g...

Powered by Blogger.