|  | 
|  | 
| вернуться в форум | Why WA#3 in Java 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);
 
 }
 }
 | 
 | 
|