In this post i will explain the solution of the following problem at hackerrank.com.
Here is the problem statement.This problem looks difficult at the first sight but it's not too difficult if you go step by step.
- Create a loop which runs through the chapters.
- Inside that loop create another loop which runs through all the problems in that particular chapter and checks whether the problem number is equal to chapter number or not.
First of all initialize two int variables to keep track of the page number and the number of special problem,i have initialized pagenum and spb as these two variables.Initialize another three variables for the number of chapters, maximum number of problems per page and the number of problems per chapter.
Take the inputs i.e. the number of chapters and the maximum number of problems per chapter. Now create a loop which runs through the chapters.
Now take another input which will be the number of problems per chapter. After that create another loop which will run through the problems in a particular chapter and check whether the problem number is equal to the page number or not. If equal than increase the variable spb by 1, if not than continue. Take a look at my solution.
Hope it helped you :)
#include <iostream>
using namespace std;
int main() {
int n,k,pagenum=1,spb=0, numprob;
cin>>n>>k;
for(int i=1;i<=n;i++){
cin>>numprob;
for(int j=1; j< =numprob; j++){ /* looping through the problems. */
if( pagenum==j )spb++; /*if problem number is equal to page number than increase spb.*/
if( j==numprob || j%k==0 ) pagenum++; /*if j reaches the problem number or j%k=0 then increase the page number.*/
}
}
cout<<spb; /*print the number of special problems.*/
return 0;
}
*****
IF YOU WANT ME TO EXPLAIN A PERTICULAR PROBLEM THAN PLEASE LEAVE A LINK TO THE PROBLEM IN THE COMMENT SECTION
*****
Super Bowl LI will be the 51st Super Bowl and the 47th modern-era National Football League .... The Touchdown Tour is a way to excite the Houston community about the 2016-2017 football season culminating in Super Bowl LI.
ReplyDeleteSuper Bowl 51
Super Bowl 51 Live
Super Bowl 51 Live Stream
Watch Super Bowl 51
Watch Super Bowl 51 Live
Super Bowl 51 Live Online
Thanks for sharing your view on this, it is really very useful.
ReplyDeleteHi admin
ReplyDeleteIts acutely impressive, that is the account you adore I agreeable it.
I accept additionally this accompanying site.
This commodity covers the recommended best practices for website design. What is a charge and what to abstain to body a acceptable looking, user affable website.
Web design brisbane
Best Regards
Lori Donna
This comment has been removed by the author.
ReplyDeleteMore appreciable. Thank you sharing
ReplyDeleteWeb Design Company in Bijapur | SEO Services in Bijapur | Web Design Companies in Bijapur | Software Companies in Bijapur
Thanks To Watch The Masters 2017 Live Stream, one of the most prestigious tournaments in golf, is set to take place this week at Augusta National Golf Club from April 6-9.
ReplyDeleteMasters 2017
The Masters 2017
Masters 2017
The Masters 2017
Masters Golf
UFC 210
UFC 210
We already know Tiger Woods won’t be Masters 2017 Live participating in the 2017 Masters, but there are still intriguing questions entering this year’s tournament.
Genesis Technologies is one of the best Web Development company in Indore and Top IT company in India which provides best IT services like Web Designing services Indore, Internet Marketing services Indore and jobs like IT jobs in Indore and PHP jobs in Indore
ReplyDeleteA week after Chavez vs Canelo went toe-to-toe in an instant classic, boxing fans get another star-studded fight when Saul “Canelo” Alvarez (48-1-1, 34 KOs) and Julio Cesar Chavez Jr. (50-2-1, 32 KOs) meet at the T-Mobile Arena in Las Vegas.
ReplyDeleteCanelo vs Chavez Jr
Chavez Jr vs Canelo
Chavez Jr vs Canelo
Little mistake:
ReplyDeleteIt should be
int main() {
int n,k,t,page=1,spb=0;
cin>>n>>k;
for(int c=1;c<=n;c++){
cin>>t;
int p;
for(p=1;p<=t;p++){
if(p==page)
spb++;
if(p==k || p%k==0)
page++;
}
if((p-1)%k!=0)//if last problem ends in the middle of the page...next chapter
page++; //should start from the next page...(p-1) is the last problem
}
cout<<spb;
return 0;
}
The SummerSlam 2017 is an upcoming professional wrestling pay-per-view (PPV) event and WWE Network event produced by WWE for the Raw and WWE SummerSlam brands. It will take place on August 20, 2017, at the Barclays Center in Brooklyn, New York. It will be the thirtieth event under the SummerSlam chronology.
ReplyDeleteWWE SummerSlam 2017
SummerSlam Live
WWE SummerSlam Live
Watch SummerSlam
Watch WWE SummerSlam
SummerSlam live Stream
WWE SummerSlam Live Stream
This comment has been removed by the author.
ReplyDelete
ReplyDeleteUFC 219
UFC 219 fight
UFC 219 fight card
UFC 219 time
UFC 219 start time
UFC 219 ppv
UFC 219 live
UFC 219 live stream
watch UFC 219
UFC 219 live feee
UFC 219 fight live
219 UFC
219 fight
219 219 fight card
219 UFC Live
219 UFC ppv
219 UFC live
ReplyDeleteGolden Globes
Golden Globes 2018 live
Golden Globes 2018 live stream
Golden Globes live
Golden Globes live stream
Golden Globe Award
Golden Globes Red Carpet
Golden Globes 2018 time
watch Golden Globes 2018
Golden Globe Award Live
Golden Globe Award 2018
Golden Globes Awards 2018
Golden Globes Awards 2018 Live
75th Golden Globe Awards
75th Golden Globes Awards
2018 Golden Globes
2018 Golden Globes Live
2018 Golden Globe Awards
Perde Modelleri
ReplyDeleteSms Onay
mobil odeme bozdurma
nft nasıl alınır
ankara evden eve nakliyat
trafik sigortası
Dedektor
Website kurma
aşk kitapları
Smm panel
ReplyDeleteSmm Panel
iş ilanları
İnstagram takipçi satın al
hirdavatciburada.com
https://www.beyazesyateknikservisi.com.tr/
servis
tiktok jeton hilesi
salt likit
ReplyDeletesalt likit
dr mood likit
big boss likit
dl likit
dark likit
2AFQ5W
adıyaman
ReplyDeletesakarya
yalova
tekirdağ
amasya
OCPL
href="https://istanbulolala.biz/">https://istanbulolala.biz/
ReplyDeleteCUV
düzce evden eve nakliyat
ReplyDeletedenizli evden eve nakliyat
kırşehir evden eve nakliyat
çorum evden eve nakliyat
afyon evden eve nakliyat
GQJNH
014BB
ReplyDeleteSilivri Parke Ustası
Samsun Evden Eve Nakliyat
Kalıcı Makyaj
Elazığ Evden Eve Nakliyat
Tekirdağ Parke Ustası
4B470
ReplyDeleteDiyarbakır Parça Eşya Taşıma
Ankara Şehir İçi Nakliyat
Manisa Lojistik
Edirne Şehir İçi Nakliyat
Malatya Şehirler Arası Nakliyat
Çankırı Şehir İçi Nakliyat
Iğdır Lojistik
Isparta Evden Eve Nakliyat
Afyon Parça Eşya Taşıma
çeşme transfer
ReplyDeletesoulmate ajans
bor yağı filtre kağıdı
yağ süzme filtre kağıdı
XXİ6S7
04DAE
ReplyDeleteElazığ Yabancı Görüntülü Sohbet
Burdur En İyi Görüntülü Sohbet Uygulaması
Kayseri Canlı Görüntülü Sohbet Siteleri
telefonda sohbet
rize canlı sohbet uygulamaları
canlı görüntülü sohbet siteleri
edirne bedava sohbet siteleri
kadınlarla rastgele sohbet
ankara ücretsiz sohbet siteleri
60492
ReplyDeleteburdur rastgele sohbet odaları
burdur bedava sohbet uygulamaları
artvin görüntülü sohbet uygulama
Tekirdağ Rastgele Görüntülü Sohbet
ığdır Canlı Görüntülü Sohbet Siteleri
chat sohbet
igdir parasız görüntülü sohbet uygulamaları
sesli görüntülü sohbet
nevşehir sohbet sitesi
7CA1F
ReplyDeleteThreads İzlenme Hilesi
Binance Hesap Açma
Bitcoin Kazma
Coin Nasıl Kazılır
Facebook Beğeni Hilesi
Bitcoin Üretme
Soundcloud Reposts Satın Al
Görüntülü Sohbet Parasız
Tiktok Takipçi Satın Al
7B024
ReplyDeletetelegram en iyi kripto grupları
binance
huobi
okex
bingx
canlı sohbet odaları
huobi
huobi
bitmex
45714
ReplyDeletekraken
gate io
güvenilir kripto para siteleri
gate io
btcturk
binance referans kimliği
copy trade nedir
referans kimligi nedir
okex
شركة تنظيف سجاد بالجبيل MARthbh2Cb
ReplyDeleteشركة عزل اسطح بالسليل TPhiiYCsSi
ReplyDeleteشركة صيانة افران CeHd2O53p3
ReplyDeleteرقم المجاري بالاحساء VWXCh2Arvd
ReplyDeleteشركة تنظيف منازل بجازان 2nY9RqeNIw
ReplyDelete0C26FA81A8
ReplyDeletetürk takipçi satın al