python 编码问题
Question:
题:
Zack has messed up all his shoes. He has N shoes (single shoe, not paired). You have to search for the partner of each shoe. Find the maximum pair you can make out of them.
扎克弄乱了他的所有鞋子。 他有N鞋(单鞋,不成对)。 您必须搜索每只鞋子的搭档。 找到您可以从中做出的最大配对 。
You will be given a description of each shoe i.e. the size of the shoes and if it is left shoes (L) or right shoes (R). Two shoes can be paired if they are having the same size and one is left L and the other is right R.
您将得到每只鞋子的描述,即鞋子的大小以及是左鞋( L )还是右鞋( R )。 如果两双鞋子的尺码相同,则可以配对,并且一只鞋子左L ,另一只鞋子R。
Input:
输入:
The first line contains a single integer N. The number of shoes Next N lines has a description for each shoe, with spaces, separated size, and L/R.
第一行包含一个整数N。 鞋子的数量接下来的N行包含每只鞋子的描述,并带有空格,分隔的大小和L / R。
5
1 L
2 R
3 L
1 R
2 L
Output:
输出:
A single integer, maximum pairs can be made out of the given shoes.
可以从给定的鞋子中制成一个整数,最大对。
2
Constraints:
限制条件:
1<=N<=1000
Shoe size will be a positive integer less than 100.
Explanation/Solution:
说明/解决方案:
In this question, we are given a number of shoes with their size and type whether it is left or right. Our aim is to make a pair of shoes which have the same size and one is left and the other is right. So we make two array one have the shoe size and other having the shoe type. Each time we compare the shoe size with other shoes and also check the types of shoes it is left or right the make one pair of shoes.
在这个问题中,我们给了许多鞋子,它们的大小和类型是左还是右。 我们的目标是制造一双尺寸相同的鞋子,一双左,另一双右。 因此,我们使两个数组中的一个具有鞋子的大小,另一个具有鞋子的类型。 每次我们将鞋子的尺码与其他鞋子进行比较,并检查鞋子的类型时,左,右都是一双鞋子。
To solve this question, we are using Python3.
为了解决这个问题,我们使用Python3。
Code:
码:
s = int(input())
arr = [ ]
brr = [ ]
p = s
while(s>0):
s-=1
a,b = input().split()
arr.append(int(a))
brr.append(b)
i,j,count=0,0,0
s = p
while(i<s-1):
j=i+1
while(j<s):
if(arr[i]==arr[j] and brr[j]!= brr[i] and brr[j]!='S' and brr[i]!='S'):
brr[i]='S'
brr[j]='S'
count+=1
break
j+=1
i+=1
print(count)
Output
输出量
6
1 L
2 L
3 L
1 R
2 R
3 R
3
翻译自: https://www.includehelp.com/python/shoes-matching-competitive-coding-questions.aspx
python 编码问题