Как понять когда она завершила ввод сообщения? Please use english. I translated your question with google translate and it said "How do you know when it has completed writing a message?". Well, it depends on the programming language you are using. Pascal: while not(eof(input)) (not sure if it was input) C: you usualy use while(!feof(stdin)) http://www.cplusplus.com/reference/cstdio/feof/ This doesn't seem to work (for me at least). C++: I think it's !cin.eof() (I've never used this one). > C: you usualy use while(!feof(stdin)) http://www.cplusplus.com/reference/cstdio/feof/> This doesn't seem to work (for me at least). This does not work if you read lines with gets and write it with puts, but feof(stdin) is works fine. May be some problems with linefeeds. Stupid MSVS. Edited by author 07.02.2013 12:20 Edited by author 07.02.2013 12:20on pascal
while not eoln do begin read(g_string); ...... ...... end; on java: Scanner scan = new Scanner(System.in); while (scan.hasNext()){ s = scan.nextLine(); } on python message = sys.stdin.readlines() and then ctrl+D to stop input not 21 passes test: using System; using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication3 { class Program { static void Main() { var f = Console.In.ReadToEnd(); f = f.ToLower(); var b = f.ToCharArray(); string c = ""; c += b[0].ToString().ToUpper(); for (var i = 1; i < b.Length - 3; i++) { if ((i + 1 != b.Length && (b[i] == '!' || b[i] == '?' || b[i] == '.'||b[i] == '-') && (b[i+3] != '-'&&b[i + 1] != '!' && b[i + 1] != '?' && b[i + 1] != '.')))
{ c += b[i]; i++; while (b[i] == ' ' || b[i] == '\t' || b[i] == '\r' || b[i] == '\n') { c += b[i]; if (i + 1 != b.Length) i++; else break; } c += b[i].ToString().ToUpper(); } else c += b[i]; } Console.WriteLine(c); } } } not 4 passes test: using System; using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication3 { class Program { static void Main() { var f = Console.In.ReadToEnd(); f = f.ToLower(); var b = f.ToCharArray(); string c = ""; for (var i = 1; i < b.Length - 1; i++) { if (b[i - 1] == '-') i--; if ((i + 1 != b.Length && i + 2 != b.Length && i + 3 != b.Length && (b[i] == '!' || b[i] == '?' || b[i] == '.' || b[i] == '-') && (b[i + 3] != '-' && b[i + 1] != '!' && b[i + 1] != '?' && b[i + 1] != '.'))) {
c += b[i]; i++; while (b[i] == ' ' || b[i] == '\t' || b[i] == '\r' || b[i] == '\n') { c += b[i]; if (i + 1 != b.Length) i++; else break; } c += b[i].ToString().ToUpper(); } else { if (i == 1) c += b[i - 1].ToString().ToUpper(); c += b[i]; } } Console.WriteLine(c); } } } Edited by author 03.01.2015 21:08 - IS IT CORRECT? - YES, IT IS. - Is it correct? - Yes, it is. Мне этот пример помог 21 тест пройти If you have this problem - remember that a sentence is ended only with "!?." Endline is not an end of a sentence 1) Input text 2) Compare each character with: letter punctuation 3) Output with changes using System; using System.Collections.Generic; namespace AntiCAPS { public class Program { public static void Main(string[] args) { bool _newSentence = true; string message = Console.In.ReadToEnd().ToLower(); List<char> punctuation = new List<char>(new char[] { '!', '.', '?' }); for (int iterable = 0; iterable < message.Length; iterable++) { if ((int)message[iterable] >= 97 && (int)message[iterable] <= 122) { if (_newSentence) { Console.Write(Char.ToUpper(message[iterable])); _newSentence = false; } else Console.Write(message[iterable]); } else if (punctuation.Contains(message[iterable])) { _newSentence = true; Console.Write(message[iterable]); } else Console.Write(message[iterable]); } } } } Edited by author 02.11.2021 00:10 как сделать ввод на питоне в этой задаче? how to make python input in this task? Example 1: WHAT?????????????????????? Example 2: ?????????????????????? And... What is the answer? Example 1: WHAT?????????????????????? result: What?????????????????????? Example 2: ?????????????????????? result: ?????????????????????? These tests might cause runtime error if there're not all conditions observed in the code. Got AC just when passed these tests, thanks Try this: aaaaa...??? aaaa aaaaa.....!!! aa right answer: Aaaaa...??? Aaaa aaaaa.....!!! Aa "You are given Angela's message, which consists of uppercase English letters,..." -> Just uppercase letters in input. Does anybody had Acces Violation? And if so , how did you fix it? If you wa, try these HELLO. WORLD - IS IT CORRECT? - YES, IT IS. thank you!This is test help me!!!))) I get AC! Thanks, My algo failed because of this case in test 2; Sorry for my bad English. I use int ch; while ((ch = System.in.read()) != -1) { // my solution System.out.print(<some char>); } System.out.println(); But I get WA #1 with or without last code line. I also used System.out.flush (without last line), but it do not help me. Use Scanner from utils,that's better and esier , than use System.in.read() HHHHHH.KJDFDKJ(newline) ADFFG right answer
Hhhhhh.Kjdfdkj adffg I WA here for five times Edited by author 25.07.2008 08:43 Edited by author 25.07.2008 08:54 My program answers right on this, but still WA#4 Thx!! Twenty times THANK YOU!!!! Edited by author 28.10.2018 18:23 Edited by author 28.10.2018 18:23 If you got WA, especially if you got WA9 First line is input string, second is answer TEST. TEST? TEST! TEST. Test. Test? Test! Test. ?????????????????????? ?????????????????????? !TEST!TEST! !Test!Test! A A TEST TEST TEST Test test test TEST T TEST Test t test Also try empty input. Edited by author 30.09.2018 19:14 #include <bits/stdc++.h> using namespace std; int main() { string s; int pe = 0; while(getline(cin, s)) { for (int i = 0; i < s.length(); i++) { if (s[i] == '.' || s[i] == '!' || s[i] == '?' || (s[i] == '-' && i )) { pe = 0; } if ((s[i] - '0' + '0' >= 65 && s[i] - '0' + '0' <= 90) && pe != 0) { s[i] = s[i] - '0' + 32 + '0'; } if (pe == 0 && s[i] != ' ' && s[i] != '.' && s[i] != '!' && s[i] != '?' && s[i] != '-') { if (s[i] - '0' + '0' > 90) { s[i] = s[i] - '0' - 32 + '0'; } pe = 1; } } cout << s << '\n'; } } Edited by author 16.08.2018 18:05 Edited by author 16.08.2018 18:05 Ohhhhh..... I find my wrong... -HI - HI WA: -Hi - Hi AC: -Hi - hi var s: array[1..50] of string; si, i1, i, c: integer; input, output: text; begin {$IFNDEF ONLINE_JUDGE} assign(input, 'input.txt'); reset(input); assign(output, 'output.txt'); rewrite(output); {$ENDIF} while not seekeof(input) do begin inc(si); read(input, s[si]); end; c := 1; for i := 1 to si do for i1 := 1 to length(s[i]) do begin if c = 0 then s[i][i1] := lowercase(s[i][i1]); if (c = 1) and (s[i][i1] <> ' ') and (s[i][i1] <> '-') and (s[i][i1] <> ':') then c := 0; if (s[i][i1] = '?') or (s[i][i1] = '.') or (s[i][i1] = '!') then c := 1; end;
for i := 1 to si do writeln(output, s[i]); {$IFNDEF ONLINE_JUDGE} close(input); close(output); {$ENDIF} end. #include<iostream> #include<conio.h> #include<string> using namespace std; char unCAPS(int state, char symbel) { char out_symb; if (((int)symbel >= 65 && (int)symbel <= 90) && state ==0) { out_symb = (char)(symbel + 32); return out_symb; }
if (((int)symbel >= 97 && (int)symbel <=122 ) && state == 1) { out_symb = (char)(symbel - 32); return out_symb; }
return symbel; } int main() { char str[10000] = { NULL }, str2[10000] = { NULL }; int state = 1; cin.get(str, 10000); for (size_t i = 0; i < strlen(str); i++) { str2[i] = unCAPS(state, str[i]); if ((int)str[i] != 32) { state = 0; } if ((int)str[i] == 46 || (int)str[i] == 33 || (int)str[i] == 63) { state = 1; }
} for (size_t i = 0; i < strlen(str2); i++) { cout << str2[i]; }
return 0; } Ты тестировал локально? Если нет, то попробуй. В http://acm.timus.ru/help.aspx?topic=cpp в самом конце указано, как пользоваться #ifndef ONLINE_JUDGE (на сервере этот код не выполнится, а у себя на компьютере тестировать удобно). И смотри, нет ли на выводе, например, лишних пробелов в конце или вроде того. You don't need conio.h You should use csting or string.h for strcpy. Did you really try to compile and run it? You shouldn't use ascii codes. "str[i] == '.'" is better then "(int)str[i] == 46". Why do you think that first non-space symbol in sentence is word? Why not "-"? You should read task carefuly. 2 lines in example is 1 test. You only process first line. I've been struggling hard to overcome WA4 and WA9... In the problem statement, it says "Sentences in a message consist of words, spaces and punctuation marks". Then I've made these test cases and got AC in one go... :) Try these cases if u get WA... Case 1: WHO ARE UUUUUUUUUUUUUUUUUUU UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU? CANT U SEE IT ? Ans: Who are uuuuuuuuuuuuuuuuuuu uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu? Cant u see it ? Case 2: WHO ARE UUUUUUUUUUUUUUUUUUU UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU? CANT U SEE IT ? Ans: Who are uuuuuuuuuuuuuuuuuuu uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu? Cant u see it ? (It looks same to case 1, but it has an initial space character in the first line and I think this was causing WA9 for me...) Case 3: AND BEING CARELESS, WE ARE DESTROYING THE EARTH. ????? WHO ARE UUUUUUUUUUUUUUUUUUU UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU? CANT U SEE IT ? WHY DID U DO THIS? UUUUUUUU UUUUUUUU IDIOT. BYE. Ans: And being careless, we are destroying the earth. ????? Who are uuuuuuuuuuuuuuuuuuu uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu? Cant u see it ? why did u do this? Uuuuuuuu uuuuuuuu idiot. Bye. Case 4: ...ARE U THERE STILL? PLEASE, ANSWER MEEEEEEEEE , ANSWER ME , ANSWER ME... PLEASE Ans: ...Are u there still? Please, answer meeeeeeeee , answer me , answer me... Please Let me know if any1 finds any error... Thanks. I found hah) Edited by author 01.05.2016 17:16 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 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]==' '"? Дякую, за тест. І що мені робити? :( Edited by author 29.04.2016 11:37 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". 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". Code: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Globalization; namespace _1601AntiCAPS { class Program { static void Main(string[] args) { string input = Console.In.ReadToEnd(); //string input; while (input != null) { Console.Write(input[0]); for (int i = 1; i < input.Length; i++) { if (input[i] >= 'A' && input[i] <= 'Z') { int c = Convert.ToInt32(input[i]); char character = (char)(c + 32); string text = character.ToString(); Console.Write(text); } else Console.Write(input[i]); } } } } } What may it be? i've try any test i can think and any test in other discussins,but still WA #11. I tested : ------- WHAT ARE YOU DOING? - I AM EATING. - really? -Yes,(new line) REALLY! - ok, i KNOW. i TRUST YOU. ------- and my program output : ------- What are you doing? - I am eating. - Really? -Yes, really! - Ok, i know. I trust you. ------- I don't know what's wrong, help, please. It must be "i trust you." not "I trust you" |
|