Created
March 3, 2016 08:02
-
-
Save jianminchen/6e4265a1d73b41f544a7 to your computer and use it in GitHub Desktop.
HackerRank HourRank 6 - Lisa's workbook - Study Code (#6)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cmath> | |
#include <cstdio> | |
#include <vector> | |
#include <iostream> | |
#include <algorithm> | |
using namespace std; | |
int n,k,j,x,ans,page,i; | |
int main() { | |
page = 1; | |
scanf("%d%d",&n,&k); | |
for (i=1 ; i<=n ; i++) { | |
scanf("%d",&x); | |
for (j=1 ; j<=x ; j++) { | |
if (page == j) ans++; | |
if (j % k == 0) page++; | |
} | |
if (x % k != 0) page++; | |
//printf("%d\n",page); | |
} | |
printf("%d\n",ans); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Julia, write your own for loop code. Get more comfortable with C++. It only takes 12 lines of code.