ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1881. Long problem statement

WA3 in C++ Anyone could help me??
Posted by zimozi 26 Jul 2015 07:24
#include <iostream>
#include <string>
using namespace std;
int main()
{
int h,w,n,page=1;
int count = 0;
int a = 0;
cin>>h>>w>>n;
string str;
for(int i = 1;i <=n;i++)
{
cin>>str;
count+= str.length()+a;
if(count> w)
{
count = str.length();
a = 1;
page++;
}
else if(count ==w)
{
    count = 0;
    a =0;
if(i<n)
    page++;
}
else
{
a++;
}
}
if(page%h==0)
cout<<page/h;
else
cout<<((page/h)+1);
return 0;
}