Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
team pair issue
#11
ok,but where to add those extra print statements and which are the right branches which could satisfy below conditions in this program:-

nput:-
First line contains one integer 1<=N<=1000,number of pairs.
Next N line contains 2 space separated integers representing a pair {i,j} in current list.

Output Format:-

Print one integer,that is minimum number of swaps needed to make the list good looking

Sample Input 1:

3
1 3
0 2
4 5


Sample Output 1:

1

Explanation:

If we swap 0 and 3 list becomes (1,0),(3,2) and (4,5),which is a good looking list.


Sample Input 2:

2
3 2
0 1

Sample Output 2:

0


Explanation:

List is already good looking.
Reply
#12
You really want us to do all the thinking for you, don't you? That's disappointing.
Reply
#13
no i don't want that but where exactly should i ake changes and what changes should i make to get this input/output results?

Thanks
Reply
#14
You're literally trying nothing to work it out. Put some effort into debugging your program if you want help.
Reply
#15
any idea how could i debug it in pycharm IDE to fix to get desired results?

Thanks
Reply
#16
What's wrong with printing, as I suggested?
Reply
#17
it's not printing as expected:-nput:-
First line contains one integer 1<=N<=1000,number of pairs.
Next N line contains 2 space separated integers representing a pair {i,j} in current list.

Output Format:-

Print one integer,that is minimum number of swaps needed to make the list good looking

Sample Input 1:

3
1 3
0 2
4 5


Sample Output 1:

1

Explanation:

If we swap 0 and 3 list becomes (1,0),(3,2) and (4,5),which is a good looking list.


Sample Input 2:

2
3 2
0 1

Sample Output 2:

0


Explanation:

List is already good looking.
Reply
#18
Sigh. We're just going around in circles here. You need to add more print statements to help you work out why that is.

Why are you not willing to do any of your own work? Repeating over and over that your program doesn't work, without showing any effort in trying the suggestions is not a good use of anyone's time.
Reply
#19
Think about it. You are using a 1D array (list) to store your numbers and define your pairs as x[n] and x[n+1]. Is this the best way, or should you use actual pairs?

What are you doing to prevent accidentally stranding numbers making the task impossible? For example, if your list has the numbers 0,1,2,3,4,5 and you have one of your pairs as 1,2, that is a "good looking pair" but 0 can never be paired to be good looking (hint - all pairs must have the even number as the lower number and the odd as lower+1).

That should get you going. Show your work along with intermediate results.
Reply
#20
(Feb-29-2020, 03:07 PM)jefsummers Wrote: Think about it. You are using a 1D array (list) to store your numbers and define your pairs as x[n] and x[n+1]. Is this the best way, or should you use actual pairs?

What are you doing to prevent accidentally stranding numbers making the task impossible? For example, if your list has the numbers 0,1,2,3,4,5 and you have one of your pairs as 1,2, that is a "good looking pair" but 0 can never be paired to be good looking (hint - all pairs must have the even number as the lower number and the odd as lower+1).

That should get you going. Show your work along with intermediate results.

I am not sure which way is best here only thing i am concerned to solve it as soon as possible,as i have been struggling with this complex problem for a long time now.if any one could please tell me exactly what corrections i should make in my existing code to get desired input/output then it would be much aprrecited.

Thanks
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Getting the maximum value:key pair from a dictionary sean1 2 1,425 Jan-17-2022, 01:04 PM
Last Post: DeaD_EyE
  How to extract specific key value pair from string? aditi06 0 2,520 Apr-15-2021, 06:26 PM
Last Post: aditi06
  Auto re-pair / re-sync Controller via Script? User3000 2 2,310 Nov-30-2020, 11:42 AM
Last Post: User3000
  Search a List of Dictionaries by Key-Value Pair; Return Dictionary/ies Containing KV dn237 19 6,696 May-29-2019, 02:27 AM
Last Post: heiner55
  Key Value Pair output UtiliseIT 9 4,691 May-03-2019, 07:30 AM
Last Post: buran
  Parsing Text file having repeated value key pair using python manussnair 3 3,271 Aug-04-2018, 11:48 PM
Last Post: micseydel

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020