I actually solved these 2 problems, the online judge judged my programs to be accepted(PE). I have tested many inputs for my programs and the output is ok - no trailing spaces, missing/extra blank lines. So why is there a PE? I use Windows - MS DOS prompt to compile and run the programs. Could the problem be due to the statements System.out.print() and System.out.println() used together? I have read in another thread in this forum that System.out.println() prints a \r\n in Windows but \n in Linux, something like that. Could this have caused the PE?
Code for 444:
[java]
ACed
[/java]
and 445:
[java]
ACed
[/java]
Last edited by chunyi81 on Sun Jan 07, 2007 10:25 am, edited 1 time in total.
You can create your own inputs/outputs.. assuming your encoding is correct since that part is rather trivial. Just use that output as your input for decoding.. =)
But, if you must insist, here's some random test data:
Thanks... my output looks good on stdout, but when I stream it to a file, it turns out I output a null character between things by accident, because I did something like:
Maybe the only trap of this problem is ASCII code values could be 2 or 3 digits. So If someone can solve this problem, he must check the code carefully.
Why do I get WA??? The code looks to work correct for all inputs I could find..[cpp]#include <iostream>
#include <map>
#include <string>
using namespace std;
string s, ans, now;
map < string, char > data;
string encode(char ch){
string out = "";
while(ch){
out = out + ((char)(ch%10 + '0'));
ch /= 10;
}
return out;
}
int main(){
data.clear();
for(char i = 'a'; i <= 'z'; i++) data[encode(i)] = i;
for(char i = 'A'; i <= 'Z'; i++) data[encode(i)] = i;
data[encode('!')] = '!';
data[encode(',')] = ',';
data[encode('.')] = '.';
data[encode(':')] = ':';
data[encode(';')] = ';';
data[encode('?')] = '?';
data[encode(' ')] = ' ';
while(getline(cin, s)){
if(s[0] >= '0' && s[0] <= '9'){
now = "";
ans = "";
for(unsigned long i = 0; i < data.size(); i++){
now = now + s;
if(data.find(now) != data.end()){
ans = data[now] + ans;
now = "";
}
}
cout << ans;
} else{
for(long i = s.size() - 1; i >= 0; i--)
cout << encode(s);
}
cout << endl;
}
Be carefully when if you declare an array to save the numbers. The size of this array must be at least 300!! (because there are a maximum of 100 characters).
I made this error and get WA to many times.
the declaration of i inside the loop isn't valid C89 (however, if this is C++ it's ok). Just declare i like the other variables.
The other was a warning about using gets, you shouldn't use that function; use fgets instead; but remember that fgets doesn't remove the last character if it is a newline (you can do that with str[strlen(str)-1] = '\0').
I tested your program with my sample inputs and the outputs were all correct, maybe you're getting a Compilation Error?