+ 1
a better way to reverse input order
It is hard to describe this in title. I have a question that if i input "A B"(both integer and separate by a space), how can I output like "B A"?
18 odpowiedzi
+ 5
Zheng-Bin Weng
Java:
Scanner scan = new Scanner (System.in);
int x = scan.nextInt ();
int y = scan.nextInt ();
System.out.println (y + " " + x);
+ 4
Why would my memory requirement grow tremendously when I read 1000 numbers? Handled as chars, 1000 numbers will take exactly twice the memory as 500 characters and 10,000 characters will take ten times as much. And it will still be a negligible amount of memory. A couple thousand characters is virtually nothing.
A maximum size of 2^64 characters would be more than 700 billion times (!) more than you need to store a 25 million digit string. I don't think they'd implement a maxium of 2^64 characters when in real life you can't even use 0.0000000000001 % of it without running out of memory...
+ 4
I am not sure if this is an improvement on memory usage, but my idea here is to consume the input string lazily, by using a generator function. So I tried to save the first string in a temp file, then print out the second string from the generator buffer, finally open the file and print the first value.
Well it works with "hello world" but I am not sure about really large data...
https://code.sololearn.com/cQ2Df16g95j6/#py
Another possibility may be to take advantage of the fact that the input values are actually numbers. So maybe encoding them to hex or something, could save some memory if they are handled as numeric representations rather than strings.
+ 3
What do you mean with reversed input?
int x = 12
int y = 35
Output: 35 12?
Or output 53 21?
+ 3
Python oneliner:
print(' '.join(input().split()[::-1]))
+ 3
This one could have been written much better, but it should be almost impossible to exceed the memory limit
https://code.sololearn.com/cuU1ry8P07Qb/?ref=app
+ 3
~ swim ~ The code handles the input as string. One char = 1 byte, 25 million chars = less than 24 MB memory
+ 2
s = '123 456'
i = s.index(' ')
print(s[i+1:], s[:i])
+ 2
import re
s = '123 456'
t = re.findall(r'\d+', s)
print(*reversed(t))
+ 1
ok, here's the example
input:
123 567
output:
567 123
The problem I encountered is the input is too long that even using string might exceed the memory limit.
p.s. the input may contain 25000000 digits per integer input.
+ 1
I've tried all method you mentioned, and they seems not usable to my problem.
They returned Memory Error on the online judge.
For a error example:
-----------------------------------------------------------------------------
Traceback (most recent call last):
File "/4539645/code_4539645.py", line 1, in
print(' '.join(input().split()[::-1]))
File "/usr/lib/python3.6/encodings/ascii.py", line 26, in decode
return codecs.ascii_decode(input, self.errors)[0]
MemoryError
-----------------------------------------------------------------------------
Actually, I'd like to know: Is there any method that I can skip first input
temporarily to output second input, and then back to output first input.
p.s. I thing I haven't mentioned: there is nothing (like '\n) in the end of the input.
That really a challenge for me, thank you for helping me!
0
This may be a useful read:
https://www.sololearn.com/learn/JUMP_LINK__&&__Python__&&__JUMP_LINK/2453/?ref=app