Не вздумайте решать задачу, оно того не стоит. я именно за этим и пришел сюда Код идеален но не проходил 5 тест. Писал на пайтоне. Просто ради эксперимента к sys.stdin.read() добавил стрип - sys.stdin.read().strip() и вуаля - AC. По условиям задачи, замечу, вроде так быть не должно. Если нужен сам рабочий код - пишите 2 11 12 aaaa bb ccc ddddddddddd eeeeeeee ff jjjjj hhhh iiiii jjjjjjjjjj kk lll Correct answer: 4 2 11 10 aaaa bb ccc ddddddddddd eeeeeeee ff jjjjj hhhh iiiii jjjjjjjjjj Correct answer: 3 2 100 12 aaaa bb ccc ddddddddddd eeeeeeee ff jjjjj hhhh iiiii jjjjjjjjjj kk lll Correct answer: 1 1 11 12 aaaa bb ccc ddddddddddd eeeeeeee ff jjjjj hhhh iiiii jjjjjjjjjj kk lll Correct answer: 7 2 13 8 aaaa bb ccccc ddddddddddddd eeeeeeee ffff jjjjj hhhhhhh Correct answer: 2 1 1 1 a Correct answer: 1 I have correct answer at all tests, but i got WA #4 i have similar problem with the WA#4 anyone can help me??? If you have WA#4, then you didn't count last partially filled line. I have correct answer at all tests, but i got WA #5... Can anyone help me? try 2 3 4 aaa aaa aaa aaa CA-2 Before I found this testcasei got WA5 then i found my mistake with this test and got AC. Good luck! Thanks!I find my mistake in last test. Maybe it will help you, try this test: 3 6 5 aaaaaa bbb cc dddd ee Correct answer is 2, after recovering this mistake I get trought WA#4 inputs of the third test? and in the 4 try this: 3 5 9 aa aa aaa aa aa aa aaa aa aaa i have passed the test you give, but i still got WA3....help //i found a silly mistake and now passed test3... but still WA for the next Edited by author 26.03.2012 11:13 Edited by author 26.03.2012 11:14 //i found a mistake again.....and then i got AC Edited by author 26.03.2012 11:20 What was your second mistake? answer: 3 для первого теста для второго 2 Edited by author 21.10.2012 12:43 You can try this test case: 3 2 6 aa a a aa aa a Correct answer: 2 Isn't corect answer 6? aa a a (not a a = 3 symbols) aa aa a Thanks Deleted Edited by author 24.08.2019 23:00 Try this test: 1 5 2 to be answer: 1 Edited by author 25.09.2015 16:26 I've got accepted after adding the condition of end of file in creating new line. May be, it will be useful. Edited by author 31.01.2016 15:50 Edited by author 31.01.2016 15:50 2 5 11 as fg asdf asdfr a qwer as s s qwer e Correct answer is 5 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; } > 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 Do you mean, why RE#12? I understand, thanks Edited by author 27.09.2017 22:28 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 How did the sample output was calculated to be 2? 1st page will have 3 lines : To be or not 2nd page will have only one line: to be Is my understanding correct? I have successfully completed all tests given in the "Discussion" but for some reason test number SIX does not think so. Maybe somebody can give me the inputs and the expected answer? Much appreciated! BUMP Ok, maybe after looking at the code anyone could tell me anything :) public class Timus {
public static void main (String []args) throws IOException { PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out)); BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String mn[] = in.readLine().split(" "); byte totalPages = 1, h = Byte.parseByte(mn[0]), // lines on a page currentLines = 1, w = Byte.parseByte(mn[1]), // symbols in a line currentSymbols = 0; short n = Short.parseShort(mn[2]);// ALL words String s = ""; // current word
for (int i = 0; i < n; i++) { s = in.readLine(); if (currentSymbols + s.length() <= w) currentSymbols += s.length() + 1; else { currentSymbols = (byte) (s.length() + 1); if (currentLines + 1 <= h) currentLines++; else { totalPages++; currentLines = 1; } } }
out.print(totalPages); out.flush(); } Pleae help. what is this test? Any input i get correct answer in my compiler.But here i get WA #10 2 4 5 a! a! a! a! a! try this, correct answer is 3, not 2 Thanks, I couldn`t understand where is a mistake) Why is it true? It should be 2, not 3! I got an AC after changing the input bufsize from 100 to 101. #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; } 5 ta satrli 3 ta ustinli listdan nechta kerak. 5 3 6 To be or not to be javob: 2 English please translate: for this testcase correct answer is 2. 5 3 6 To be or not to be Can not get past this one, all tests in the discussion are passed correctly. Can anyone hint on why test #3 may be failed? Maybe you are adding a 'space' after the last word too. Space should not be counted after the last word. import java.util.*; public class Test_1874 { public static void main(String[] args) { @SuppressWarnings("resource") Scanner s = new Scanner(System.in); int h, w, n; h = s.nextInt(); w = s.nextInt(); n = s.nextInt(); String[] a = new String[n]; for (int i = 0; i < n; i++) { a[i] = s.nextLine(); if (a[i].isEmpty()) { a[i] = s.nextLine(); } } if (n == 1) { System.out.println("1"); return; } int b, c = 0, d = 0, list = 0, page = 0; for (int i = 0; i < n; i++) { b = (a[i].length() + 1); if (i == 0) { c = a[i + 1].length(); if (b + c == w) { list++; } else if (b + c < w) { d = b + c; c = a[i + 2].length(); if ((d + c) == w) { list++; } else if ((d + c) < w) { } else { list++; } } else { list++; } } else { if ((b + d) == w) { list++; } else if ((b + d) < w) { d = d + b; c = a[i + 1].length(); if ((d + c) == w) { list++; } else if ((d + c) < w) { } else { list++; } } else { list++; } } if (list == h) { page++; list = 0; } else if (i == (n - 1)) { if(list>=1){ page++; }
} } System.out.println(page); } } all test that i did was correct but i received Wrong answer 1. all tests that writed people i did and they was correct import java.util.Scanner; public class Problem_1881 { public static void main(String[] args) { Scanner in=new Scanner(System.in); int h,w,n,i,p,ans,SL,h1; ans=SL=h1=0; p=-1; ..... Edited by author 22.03.2014 20:32 resolved Edited by author 09.01.2014 18:28 I have a problem with 5 test case. Firs I had Runtime Error, when I add lines: if(nextWord == null) continue; Runtime Error changed to WA. I'm using Java and i read my input as follow: StreamTokenizer in = in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in))); private static int nextInt() throws IOException { in.nextToken(); return (int) in.nval; } private static String nextString() throws IOException { in.nextToken(); return in.sval; } Dear Colleagues, It's occurring a weird situation: on my notebook, compiling using this Online Judge way, my java code for this problem works fine and gives the correct answers. When i submit it, however, online judge accuses of "Runtime Error". It follows below my "java version": "java version "1.7.0_01" # At Ubuntu 11.10 Java(TM) SE Runtime Environment (build 1.7.0_01-b08) Java HotSpot(TM) 64-Bit Server VM (build 21.1-b02, mixed mode)" Can anyone explain why "Runtime Error" in Online Judge? I'm using only notepad. 29 lines. Got AC after first sending. :-) This problem is so easy, so you should not think that all this is because you are a true-coder. we so proud of you. better tell what you did for solve that problem except just telling why you awesome, coz it does not make other people happy. WA#4 was because I didn't count last partially filled line. WA#10 was because I've got overflow in the following test: 1 3 4 a aaa aaa aaa Should be 4, but I had 2. |
|