Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8090229
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T19:39:22+00:00 2026-06-05T19:39:22+00:00

I am trying to solve this problem http://www.spoj.pl/problems/PEBBMOV/ . I think I have the

  • 0

I am trying to solve this problem http://www.spoj.pl/problems/PEBBMOV/. I think I have the right algorithm, that is not the point of this question. This problem has a weird input file to it. The input for one test case should be of the form
n a1 a2 a3 …an. (all ints)

The problem here is that , there are stray newline characters etc in between the a[i]s. I need to be able to skip such newlines and collect all a[i]s belonging to one test case at a place. How do I know all this? Well a string of WAs and Runtime Errors , plus some research on the forums. I have the following python code to try to do this, except that i seem to be faltering at crucial places and just cant get it done. I hope to have the appropriate input lines in the list lines[] at the end of the input reading.

Could someone please tell me my mistake(s) here.? Or suggest a better approach?. Thanks in advance..

import sys
#data = sys.stdin.readlines()
#lines = inp.split('\n')
data = sys.stdin.read()
pos = 0
lno = 0

lines = []
while pos<len(data):
    while not data[pos].isdigit():
                   pos = pos + 1
num =data[pos]
print num
cur = pos + 1
numbers_collected = 0

x = [] # temp list
y = []
while numbers_collected < num:

    if cur<len(data) and data[cur].isdigit():
        y.append(data[cur])
        cur = cur + 1
        numbers_collected += 1
    else:
        if cur<len(data)and numbers_collected < num:
            cur = cur + 1
        else:
            break
print x
pos = cur
x.extend(y)
lines.extend(x)



for line in lines:
    print line
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T19:39:24+00:00Added an answer on June 5, 2026 at 7:39 pm

    Does this help you answer your question?

    In [1]: s1 = "1\n2\n\n3\n\n\n4\n\n\n\n5\n\n\n\n\n6"
    
    In [2]: s1
    Out[2]: '1\n2\n\n3\n\n\n4\n\n\n\n5\n\n\n\n\n6'
    
    In [3]: s1.splitlines()
    Out[3]: ['1', '2', '', '3', '', '', '4', '', '', '', '5', '', '', '', '', '6']
    
    In [4]: [elem for elem in s1.splitlines() if elem]
    Out[4]: ['1', '2', '3', '4', '5', '6']
    

    Without seeing example input it’s difficult to answer the question. However, the SPOJ problem page does not provide example input, so the OP can’t provide something that isn’t available.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was trying this problem, http://www.spoj.pl/problems/TWOSQ/ . We have to find the number of
I'm trying to solve this problem : http://uva.onlinejudge.org/external/7/732.html . For the given example, they
I am trying to solve this problem. I have a series of SELECT statements
I'm trying to solve this problem, its not a homework question, its just code
I have been trying to solve this problem for a while, but couldn't with
I'm trying to solve this problem for a long time. I have 2 forms,
I am trying to solve this exponentiation problem . Here is the code that
I have been trying to solve this problem for three days now, it's really
I'm trying to solve the following problem: I have a download button that when
I am trying to solve this problem from SPOJ, it's a dynamic programming problem,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.