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

ramon93i7 WA 12 [4] // Problem 1881. Long problem statement 16 Apr 2012 12:32
What's wrong in my code?
<
#include <stdio.h>
#include <string.h>

int main() {
        int i,h,w,n,tmp;
    int curLen = 0, curNumStr = 0;
    char s[105];
    scanf("%d%d%d\n",&h,&w,&n);
    for(i = 0; i < n; i ++) {
        gets(s); //scanf("%s",s);
        tmp = strlen(s);
        if(curLen)
            curLen += 1 + tmp;
        else
            curLen += tmp;
        if(curLen / w){
            curNumStr += curLen / w;
            if(curLen % w)
                curLen = tmp;
            else
                curLen = 0;
        }
    }
    if(curLen)
        curNumStr ++;

    tmp = curNumStr / h;
    if(curNumStr % h)
        tmp ++;
    printf("%d",tmp);
    return 0;
}
>
DrunkBear Re: WA 12 [3] // Problem 1881. Long problem statement 27 Sep 2017 21:25
What's wrong with my code too?

h,w,n=map(int,input().split())
a=[]
for i in range(n):
    a.append(input())
lines=0
pag=0
while len(a)>0:
    if len(a)!=1:
        length=-1
        while length<w:
            length+=len(a[0])+1
            b=a[0]
            a.remove(a[0])
        if length>w:
            a.reverse()
            a.append(b)
            a.reverse()
        lines+=1
    else:
        lines+=1
        a.remove(a[0])

if lines%h==0:
    pag=lines//h
else:
    pag=lines//h+1
print(pag)


Edited by author 27.09.2017 21:28
Mahilewets Nikita [BSUIR] Re: WA 12 [1] // Problem 1881. Long problem statement 27 Sep 2017 22:03
Do you mean, why RE#12?
DrunkBear Re: WA 12 // Problem 1881. Long problem statement 27 Sep 2017 22:27
I understand, thanks




Edited by author 27.09.2017 22:28
Mahilewets Nikita [BSUIR] Re: WA 12 // Problem 1881. Long problem statement 27 Sep 2017 22:14
You are removing a[0], not element with index 0
So if there are several elements having the same value as a[0] they would be removed together with a[0]
So they would be not processed

Also I strongly recommend  you not to store the entire input but process data just in time