|
|
вернуться в форумWA9 WHY??? new one but still WA9 package banky; import java.util.*; public class test1 { private static Scanner scan; public static void main(String [] args){ scan = new Scanner(System.in); int k=0; int r=0; int pr=0; while (scan.hasNext()){ String s = scan.nextLine(); //s = s.toUpperCase(); s = s.toLowerCase(); char c [] = s.toCharArray(); if (k<=0||r>0) c[0] -= 32; int i ; for(i=1;i<s.length();i++){ if ((c[i] == 46) || (c[i] == 33) || (c[i] == 63)) {pr= 1; c[i]=c[i];} else if (pr==1&&c[i]!=32) { c[i] -= 'a' - 'A'; pr = 0;}} for(i=0;i<s.length();i++){ if ((c[i] == 0)|| (c[i] == 14) || (c[i] == 1) || (c[i] == 31)) c[i] += 'a' - 'A';} for(i=1;i<s.length();i++){ if (((c[i-1]< 'a')&&(c[i-1]>='A'))&&((c[i]< 'a')&&(c[i]>='A'))) {c[i] += 'a' - 'A';}}
if ((c[s.length()-1] == 46) || (c[s.length()-1] == 33) || (c[s.length()-1] == 63)) {r=r+1;} else {r=0;} //System.out.println(k); //System.out.println(r); System.out.println(c); k=k+1; } } } Edited by author 30.04.2016 13:09 Re: WA9 WHY??? You are checking the only prev char for end of sentence. Why? Try "HERE!!! IS!!!!! TEST!!!!" P.S. Why "c[i]==32" better then "c[i]==' '"? Re: WA9 WHY??? Дякую, за тест. І що мені робити? :( Edited by author 29.04.2016 11:37 Re: WA9 WHY??? Implement state machine, ~2 states: 1) "at sentence begin", if char is alpha then it uppercased, state switched to "inside sentence" 2) "inside sentence", if char is alpha it lowercased; if char is ".?!" state switched to "at sentence begin". Re: WA9 WHY??? Thank you for help. But I am only beginer in java so i cant jet deal with this state machine Implement state machine, ~2 states: 1) "at sentence begin", if char is alpha then it uppercased, state switched to "inside sentence" 2) "inside sentence", if char is alpha it lowercased; if char is ".?!" state switched to "at sentence begin". |
|
|