Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

USACO Code Submission Problem – Output File Missing

I’ve started practicing for the USACO contest tomorrow, I’m relativly new so I’m not too familiar with their input/output methods. Here’s the code I submitted to the website

n = int(input())
a = input()
b = input()

swap_number = 0
a_list = []
b_list = []

for i in range(n):
  if a[i] != b[i]:
    a_list.append(a[i])
    b_list.append(b[i])

one_value = 0
two_value = 0

for x in range(len(a_list)):
  if a_list[x] == "H":
    one_value += 1
  else:
    two_value += 1


list = [one_value,two_value]
list.sort()

swap_number = list[0] + (list[1]-list[0])

print(swap_number)

after loading for a couple minutes, it displayed:
Your output file breedflip.out:
[File missing!]

I rewrote, retested every problem using this simple code, but still receive the same error
Would this code not create an output file and how can I put the outputted answer in the file

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Try to add these two lines in your beginning of codes: (just test and it passed with my revised code) Your code might not be working!


import sys

sys.stdin = open('breedflip.in', 'r')
sys.stdout = open('breedflip.out', 'w')

n = int(input())
a = list(input())   # list
b = list(input())
...........
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading