UVA 12482 - Short Story Competition

UVA Sep 1, 2020

Problem PDF

Solution:

#include<iostream>
#include<algorithm>
#include<sstream>
#include<fstream>
#include<utility>
#include<cstdlib>
#include<cstring>
#include<string>
#include<bitset>
#include<vector>
#include<cstdio>
#include<cctype>
#include<cmath>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#define ll long long
#define sc scanf
#define pf printf
#define pi 2*acos(0.0)
using namespace std;
int main()
{
    int n,l,c;
    string s;
    while(cin>>n>>l>>c)
    {
        int len,line=1,page=0;
        cin>>s;
          len=s.size();
        for(int i=0;i<n-1;i++)
        {
            cin>>s;
            if((len+s.size()+1)<=c)
            {
                len+=s.size()+1;
            }
            else
            {
                line++;
                len=s.size();
            }
        }
        page=line/l;
        if(line%l)
            page++;
        cout<<page<<endl;

    }
    return 0;
}
https://github.com/Shipu/OnlineJudgeProblemSolutionWithCPlusPlus/tree/master/uva/12482/12482.cpp

Tags

Great! You've successfully subscribed.
Great! Next, complete checkout for full access.
Welcome back! You've successfully signed in.
Success! Your account is fully activated, you now have access to all content.