Page 5 of 5
Why time limit?
Posted: Wed Aug 27, 2014 2:03 pm
by letrunghieu
Code: Select all
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main()
{
string s;
ifstream InFile("INPUT.inp");
//InFile.open("INPUT.inp",ios::in);
while(1)
{
if(InFile.eof())
{
//InFile.close();
return 0;
}
getline(InFile, s);
int len = s.length();
for(int i = 0;i<len;i++)
cout << char(int(s[i]) -7);
cout << endl;
}
return 0;
}
Re: 458 - The Decoder
Posted: Wed Aug 27, 2014 6:46 pm
by lighted
Terminating condition
InFile.eof() never occurs, so you have infinite loop.
Don't read from file. Read from standart input. Look here
http://ideone.com/GaA0b7
Re: 458 - The Decoder
Posted: Sun Aug 31, 2014 8:51 pm
by Shihab
did u print a newline?
Re: 458 - The Decoder
Posted: Mon Oct 06, 2014 8:56 pm
by Astaldo
To all those who are trying this problem in Java... it was a huge headache:
Code: Select all
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
/**
* UVa Online Judge: Problem 458 (Accepted).
*
* @author Astaldo
*/
public class Main {
/**
* Start of the program. Gets input encoded messages and decode them.
*
* @param args -> not used.
*/
public static void main (String args []){
DataInputStream input = new DataInputStream(System.in);
DataOutputStream output = new DataOutputStream(System.out);
String line = read(input);
while (!line.isEmpty()){
try {
output.writeBytes(decode(line) + "\n");
output.flush();
} catch (IOException ioe) {}
line = read(input);
if (line == null)
line = "";
}
}
/**
* Reads an input line.
*
* @param input -> DataInputStream.
* @return the line read or a EOF if not found input line.
*/
@SuppressWarnings("deprecation")
public static String read (DataInputStream input){
String line = null;
try {
line = input.readLine();
} catch (IOException ioe){}
return line;
}
/**
* Decodes a given message calculating the char by char sum with the encode integer
* (in this case, -7).
*
* @param msg -> String to decode.
* @return the decoded message.
*/
public static String decode (String msg){
String aux = "";
int encode = -7;
char message [] = msg.toCharArray();
for (int i = 0; i < msg.length(); i++)
message[i] += encode;
for (int i = 0; i < msg.length(); i++)
aux += message[i];
return aux;
}
}
Good luck!
Re: 458 - The Decoder
Posted: Mon Oct 27, 2014 8:16 pm
by murtuza
why TL please help me
Code: Select all
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner in=new Scanner(System.in);
while(in.hasNext()){
String s;
s=in.nextLine();
for(int i=0;i<s.length();i++)
{
//char t=(char)((int)s.charAt(i)-7);
System.out.printf("%c",s.charAt(i)-7);
}
System.out.println();
}
}
}
Re: 458 - The Decoder
Posted: Tue Oct 28, 2014 11:39 am
by lighted
I modified your code and now it gives WA.
http://ideone.com/yphgE8
Re: 458 - The Decoder
Posted: Tue Oct 28, 2014 1:17 pm
by lighted
delete
Posted: Wed Nov 12, 2014 11:38 am
by xrenon
delete
Re: 458 - The Decoder
Posted: Wed Nov 12, 2014 5:15 pm
by lighted
https://codercodesit.wordpress.com/tag/458/
Finally i managed to get ACCEPTED in Java using BufferedReader.
For all who still get WA in Java with BufferedReader.
http://ideone.com/84DCXo
Also you face this problem with 10194, 10197 and other uva problems.
http://acm.uva.es/board/viewtopic.php?f ... 30#p140856
Re: 458 - The Decoder
Posted: Thu Nov 13, 2014 4:33 am
by xrenon
DELETED
Re: 458 - The Decoder
Posted: Thu Nov 13, 2014 11:01 am
by lighted
xrenon! Try to read links above before posting. I posted those links especially for people having troubles in accepting java code like you.

Re: 458 - The Decoder
Posted: Mon Aug 29, 2016 6:30 pm
by astandrik
Anyone pls help. Always getting WA
Code: Select all
import sys
f = sys.stdin
c = f.read(1)
while c != '':
o = ord(c)
if o == 10 or o == 13:
sys.stdout.write(c)
elif o < 135:
sys.stdout.write(chr(o - 7))
c = f.read(1)
sys.stdout.write('\n')
exit(0)