Skip to content

Instantly share code, notes, and snippets.

@jianminchen
Created March 3, 2016 08:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jianminchen/6e4265a1d73b41f544a7 to your computer and use it in GitHub Desktop.
Save jianminchen/6e4265a1d73b41f544a7 to your computer and use it in GitHub Desktop.
HackerRank HourRank 6 - Lisa's workbook - Study Code (#6)
#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;
}
@jianminchen
Copy link
Author

Julia, write your own for loop code. Get more comfortable with C++. It only takes 12 lines of code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment