|  | 
|  | 
| вернуться в форум | WA 12 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;
 }
 >
Re: WA 12 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
Re: WA 12 Do you mean, why RE#12?Re: WA 12 You are removing a[0], not element with index 0So 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
Re: WA 12 I understand, thanks
 
 
 
 Edited by author 27.09.2017 22:28
 | 
 | 
|