Chuyển đổi mã python sang công cụ trực tuyến java

Ideone là gì? Ideone là một công cụ biên dịch và sửa lỗi trực tuyến cho phép bạn biên dịch mã nguồn và thực thi trực tuyến bằng hơn 60 ngôn ngữ lập trình. Làm thế nào để sử dụng Ideone? Chọn ngôn ngữ lập trình, nhập mã nguồn với dữ liệu đầu vào tùy chọn. và bạn đã sẵn sàng để đi

xin chào, tôi có một số đoạn mã python mà tôi cần chuyển đổi sang java.

con trăn java

2 0

Chia sẻ

  • 27 Cộng tác viên
  • 31 Trả lời
  • 148K Lượt xem
  • 16 năm Khoảng thời gian thảo luận
  • Bài đăng mới nhất Bài đăng mới nhất của eliasarximan

eliasarximan đã bình luận. ai đó có thể giúp tôi không? . Làm ơn giúp tôi. Mã Python của tôi. def import_file(tệp). với o +0

Câu trả lời được đề xuất

Đã trả lời bởi alc6379 120 trong một

Tại sao làm vậy?

http. //www. jython. tổ chức/

Đó là một trình thông dịch python được viết bằng Java thuần túy. hấp dẫn

Đã trả lời bởi kyle. tk 0 trong một

đăng mã. cũng thấy những gì chúng ta có thể làm

Tất cả 31 câu trả lời

Chuyển đổi mã python sang công cụ trực tuyến java

alc6379 120 Cookie. Thế là xong Đồng nghiệp nhóm

17 Năm Trước

Tại sao làm vậy?

http. //www. jython. tổ chức/

Đó là một trình thông dịch python được viết bằng Java thuần túy. hấp dẫn

0 0

Chia sẻ

Chuyển đổi mã python sang công cụ trực tuyến java

shak187 0 Áp phích dành cho người mới

17 Năm Trước

nó là gì mà tôi cần phải chuyển đổi nó thành java thích hợp để nó có thể chạy trên phần mềm java thực tế mặc dù vậy, cảm ơn vì liên kết

0 0

Chia sẻ

Chuyển đổi mã python sang công cụ trực tuyến java

kyle. tk 0 Áp phích dành cho người mới

17 Năm Trước

đăng mã. cũng thấy những gì chúng ta có thể làm

1 0

Chia sẻ

Ashish_50 đã nhận xét. arr=[] l=int(input("Nhập độ dài mảng. ")) cho tôi trong phạm vi (l). ele=int(input("Nhập phần tử. ")) mảng. nối thêm(ele) min_jumps_array= +0

Chuyển đổi mã python sang công cụ trực tuyến java

shak187 0 Áp phích dành cho người mới

17 Năm Trước

ĐÂY LÀ MÃ

import javax.swing.JOptionPane;

//=== CONSTANTS ====
public class version21
{
//decalaration
    private int LOWER_EASY = 0;
    private int UPPER_EASY = 100;
    private boolean FIRST = true;
    private boolean OTHER = false;
    String numG;
    private int numGoes, totalGoes, numCorrect;
    private boolean start, carryOn;
    private int num;
    private int guess,getGuess;
    private boolean playAgain;
    private boolean tryAgain;
    private boolean retValue;
    private boolean numGuesses;

    public static void main(String [] args)
    {
    // === declare and initialise main's local variables ===
        numGoes = 0;  //number of times the game is played
        totalGoes = 0;   // total number of guesses made
        start = true;
        numCorrect = 0;

    // === BEGIN MAIN LOOP FOR THE GAME ===

        while (start){
            numGuesses = 0;
            boolean carryOn = true;
            String s;
            int guess = Integer.parseInt(JOptionPane.showInputDialog(null,"pick a number between 1 and 100"));
            int num = Random.nextInt(UPPER_EASY-LOWER_EASY)+LOWER_EASY; //range between LOWER_EASY and UPPER_EASY
            System.out.println("For testing purposes the num generated is: "+num);
            numGuesses++;
        }//while (start)
        // === GET USERS GUESSES. LOOP 'TIL THEY EITHER GET IT RIGHT OR GIVE UP ===

        while (guess != num && carryOn)
        {
            carryOn = tryAgain(guess, num);
            if (carryOn)
            {
                guess = getGuess(OTHER);
                numGuesses += 1;
            }//if (carryOn)
        }//while guess

        if (guess == num)
        {
            numG = numGuesses;
            String sInput = JOptionPane.showMessageDialog ("Great! You got it right in " + numG + " goes!");
            numCorrect += 1;

            totalGoes += numGuesses;

            start = playAgain();
        }//if
   // === END MAIN-LOOP

        outputResults(numCorrect, numGoes, totalGoes);

    public static int getGuess()
    {
        System.out.println ( ".. getting guess");
        guess = 0; // some dummy value to pass back
        JOptionPane.showInputDialog(null, "guess");
    }//getguess()

    public static String tryAgain()
    {
        System.out.printLn(" ... seeing if user wants to guess again");
        retValue = false; // some dummy value to pass back
        return JOptionPane.showMessageDialog(null, "retValue");
    }//tryagain()

    public static String playAgain()
    {
        retValue = false; // some dummy value to pass back
        System.out.printLn( "That Game's over... checking for play again .. ");
        return JOptionPane.showMessageDialog(null, "retValue");
    }//playagain()

    public static int outputResults(String correct, int timesPlayed, int totalAttempts)
    {
        System.out.printLn( "Thanks for playing. hope you had fun...");
        System.out.printLn( "You played" + timesPlayed +"times.");
        System.out.printLn( "You guessed correctly" + correct + "times, and you gave up" + timesPlayed - correct + "times");
    }//outputresults()

    public static String validResponse( )
        {
        System.out.println( "...checking that value supplied by user is in the right range");
        ok = true; // some dummy value to pass back
        return JOptionPane.showMessageDialog(null, "ok");
        }//validresponse()




}//Version21

0 0

Chia sẻ

Được chỉnh sửa 9 năm trước bởi TrustyTony vì. định dạng cố định

Chuyển đổi mã python sang công cụ trực tuyến java

cornae@face 0 Áp phích dành cho người mới

7 năm trước

def Get_Data(Input):
         New_List = []
             for i in range(len(Input)):
                 New_List.append(Input[i])
         return Check_Twain(New_List)

     def Check_Twain(List_Data):
         for b in range(int((len(List_Data)/2)+1)):
             for a in range(len(List_Data)-1):
                 if List_Data[a] == "(" and List_Data[a+1] == ")" or List_Data[a] == "[" and List_Data[a+1] == "]" or List_Data[a] == "{" and List_Data[a+1] == "}":
                     List_Data.pop((a+1))
                     List_Data.pop(a)
                     break
         return len(List_Data)  

     Input_Number = int(input("กรุณาใส่จำนวนข้อมูลที่ต้องการตรวจสอบ : "))
     List_Data = []

     for i in range(Input_Number):
         List_Data.append(input("กรุณาใส่ข้อมูลที่ต้องการตรวจสอบ : "))

     for s in range(len(List_Data)):
         if Get_Data(List_Data[s]) > 0 :
             print (" no")
         else: 
             print(" yes")

0 0

Chia sẻ

Chuyển đổi mã python sang công cụ trực tuyến java

Arpita_1 0 Áp phích dành cho người mới

5 năm trước

tôi cần chuyển mã python sang java

0 1

Chia sẻ

Chuyển đổi mã python sang công cụ trực tuyến java

Arpita_1 0 Áp phích dành cho người mới

5 năm trước

import random
import string

def printAll(conversation):
   for line in conversation:
       print (line)

def main():
   cannedlist = ["How are you?", "Why is the sky blue?" , "How's the
weather?" , "When will it end?" , "Why are we here?" , "Sounds good!",
"That's great!", "What time is it?"]
   num_canned = len(cannedlist)
   response = input("How many rounds of conversation?")
   conversation = []
   number = random.randrange(0,num_canned)
   computer = cannedlist[number]
   print (computer)
   conversation.append(computer)

   # perform specified number of interaction rounds
   for interaction in range(eval(response)):
       user = input("")
       conversation.append(user)

       # search for mirror words and construct response
       userwords = user.split()
       mirror_words_found = False
       computer = ""
       for word in userwords:
           if word == "I":
               new_word = "You"
               mirror_words_found = True;
           elif word == "you":
               new_word = "I"
               mirror_words_found = True;
           elif word == "You":
               new_word = "I"
               mirror_words_found = True;
           elif word == "am":
               new_word = "are"
               mirror_words_found = True;
           elif word == "are":
               new_word = "am"
               mirror_words_found = True;
           elif word == "me":
               new_word = "you"
               mirror_words_found = True;
           elif word == "you're":
               new_word = "I'm"
               mirror_words_found = True;
           elif word == "I'm":
               new_word = "You're"
               mirror_words_found = True;
           else:
               new_word = word
           computer = computer + new_word + " "
       computer = computer.replace(".","?");
       computer = computer.replace("!","?");

       # if we found no mirror words, use a canned response instead
       if not mirror_words_found:
           number = random.randrange(0,num_canned)
           computer = cannedlist[number]

       # use whatever response we came up with
       print (computer)
       conversation.append(computer)

   # end the conversation
   computer = ("Goodbye!")
   print (computer)
   conversation.append(computer)
   print()
   print()
   printAll(conversation)

main()     
print (line)

   # search for mirror words and construct response
   userwords = user.split()
   mirror_words_found = False
   computer = ""
   for word in userwords:
       if word == "I":
           new_word = "You"
           mirror_words_found = True;
       elif word == "you":
           new_word = "I"
           mirror_words_found = True;
       elif word == "You":
           new_word = "I"
           mirror_words_found = True;
       elif word == "am":
           new_word = "are"
           mirror_words_found = True;
       elif word == "are":
           new_word = "am"
           mirror_words_found = True;
       elif word == "me":
           new_word = "you"
           mirror_words_found = True;
       elif word == "you're":
           new_word = "I'm"
           mirror_words_found = True;
       elif word == "I'm":
           new_word = "You're"
           mirror_words_found = True;
       else:
           new_word = word
       computer = computer + new_word + " "
   computer = computer.replace(".","?");
   computer = computer.replace("!","?");

   # if we found no mirror words, use a canned response instead
   if not mirror_words_found:
       number = random.randrange(0,num_canned)
       computer = cannedlist[number]

   # use whatever response we came up with
   print (computer)
   conversation.append(computer)

0 1

Chia sẻ

Chuyển đổi mã python sang công cụ trực tuyến java

MAYANK_11 0 Áp phích dành cho người mới

4 năm trước

t = int(input())
for _ in range(t):
n,k = map(int,input().split())
li = list(map(int,input().split()))
li.sort(reverse=True)
j = 0
while k+j-1

0 0

Chia sẻ

Chuyển đổi mã python sang công cụ trực tuyến java

gabriel_18 0 Áp phích dành cho người mới

3 năm trước

Tôi cần chuyển mã java sang python.
nhập java. sử dụng. Máy quét;

lớp công khai Chính {

public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = Integer.parseInt(sc.nextLine());
    int[] hours = new int[n];
    if (n <= 31) {
        inputHours(hours,n,sc);
        workedHours(hours,n);
    }
}

private static void workedHours(int[] hours, int n) {
    int sum = 0;
    for (int i = 0; i < hours.length; i++) {
        if (hours[i] != 8 && hours[i] > 8) {
            sum += hours[i] - 8 ;
        }
    }
    System.out.println(sum);
}

private static void inputHours(int[] hours, int n, Scanner sc) {
    for (int i = 0; i < hours.length; i++) {
        hours[i] = Integer.parseInt(sc.nextLine());
        System.out.println(hours[i]);
    }
}

0 1

Chia sẻ

Chuyển đổi mã python sang công cụ trực tuyến java

cetpainfotech 0 Áp phích dành cho người mới

2 năm trước

Đó là một đoạn trích từ câu trả lời stackOverflow. Thẳng thắn mà nói, không có công cụ trực tuyến nào như vậy hoặc bất kỳ thứ gì có thể chuyển đổi trực tiếp mã python của bạn thành mã java và cung cấp cho bạn kết quả mong muốn chính xác mà bạn có thể đã nhận được từ mã python của mình

0 0

Chia sẻ

Chuyển đổi mã python sang công cụ trực tuyến java

memelord 0 Áp phích dành cho người mới

2 năm trước

Tôi cũng cần chuyển mã này sang Java. Sẽ được đánh giá cao nếu ai đó có thể làm điều này cho tôi

#creating the array we will be using
myArray = [ ]

#defining the method that takes the integers from the file and inputs them into the array
def filetoArray(x):
  openFile = open("array.txt", "r")
  integers = openFile.read()
  print(integers)
  openFile.close()

#prints the array
def printArray(x):
  for i in x:
    print(i, end=' ')

#reverses the array
def reverse(x):
  openFile = open("array.txt", "r")
  reverseIntegers = openFile.read()
  print(reverseIntegers[::-1])
  openFile.close()

#using the method that takes the integers from the file and inputs them into the array and prints it
print("Array Before Reversing:")
filetoArray(myArray)
printArray(myArray)

#using the method that reverses the array and prints it
print("\nArray After Reversing:")
reverse(myArray)

0 0

Chia sẻ

Chuyển đổi mã python sang công cụ trực tuyến java

JamesCherrill 4,667 Người đăng có giá trị nhất Người kiểm duyệt Người đăng nổi bật<

2 năm trước

tôi có thể làm điều đó. Bạn trả bao nhiêu tiền?

2 0

Chia sẻ

Chuyển đổi mã python sang công cụ trực tuyến java

Mahesh_27 0 Áp phích dành cho người mới

2 năm trước

từ biên dịch nhập lại
candidates = ["doconeument", "documdocumentent", "documentone", "pydocdbument", "documentdocument", "hansi"]
word = "document"
def strip_word(word, candidate):
regex = biên dịch("^(. )" + "(. )". tham gia (từ) + "(. *)$")
match = regex. khớp(ứng cử viên)
nếu không khớp.
trả lại ứng viên
return strip_word(word, "". tham gia (trận đấu. nhóm()))
cho cand trong các ứng cử viên.
print(f"'{cand}' -> '{strip_word(word, cand)}'")

0 0

Chia sẻ

Đã chỉnh sửa 2 năm trước bởi Mahesh_27 bởi vì. Muốn giải pháp tương tự trong java Muốn thoát khỏi tài liệu

Chuyển đổi mã python sang công cụ trực tuyến java

Meet_3 0 Áp phích dành cho người mới

2 năm trước

Tôi cần chuyển mã python sang mã java
Nhấp vào đây

0 1

Chia sẻ

Chuyển đổi mã python sang công cụ trực tuyến java

chd_1 0 Áp phích dành cho người mới

2 năm trước

Tôi cần chuyển đổi mã python trong java

0 1

Chia sẻ

Chuyển đổi mã python sang công cụ trực tuyến java

D_6 0 Áp phích dành cho người mới

1 năm trước

class Solution:
def replaceElements(self, arr: List[int]) -> List[int]:
    return[*itertools.accumulate([-1] + arr[::-1], max)][::-1][1:]

0 0

Chia sẻ

Chuyển đổi mã python sang công cụ trực tuyến java

Daniela_3 15 Áp phích dành cho người mới

1 năm trước

/Nhanh lên, tôi cần chuyển mã này sang java, cảm ơn/

lớp Cuenta()

def __init__(self,titular,cantidad=0):
    self.titular=titular
    self.__cantidad=cantidad

@property
def titular(self):
    return self.__titular

@property
def cantidad(self):
    return self.__cantidad

@titular.setter
def titular(self,titular):
    self.__titular=titular


def mostrar(self):
    return "Cuenta\n"+"Titular:"+self.titular.mostrar()+" - Cantidad:"+str(self.cantidad)

def ingresar(self,cantidad):
    if cantidad > 0:
        self.__cantidad = self.__cantidad + cantidad

def retirar(self,cantidad):
    if cantidad > 0:
        self.__cantidad = self.__cantidad - cantidad

1 0

Chia sẻ

lợi nhuận đã nhận xét. Hãy nhớ rằng việc đăng bài thảo luận dưới 15 tuổi chỉ có vậy. Giấu kín. +15

Chuyển đổi mã python sang công cụ trực tuyến java

Izzat_2 15 Áp phích dành cho người mới

1 năm trước

#. /bin/trăn

Để kiểm tra chức năng gửi thời gian thực cdr

chuỗi nhập nhập urllib2 thời gian nhập ổ cắm nhập
port = raw_input("Vui lòng nhập cổng liên kết như. 1000\n")
#wait connect
def test().
máy chủ = ổ cắm. ổ cắm (ổ cắm. AF_INET,ổ cắm. SOCK_STREAM)
địa chỉ = ('192. 168. 124. 16', int(port)) //địa chỉ IP cục bộ
máy chủ. liên kết (địa chỉ)
máy chủ. nghe(10)
trong khi 1.
s,addr=server. chấp nhận()
dữ liệu = s. recv(2048) in (dữ liệu)
s. close()
test()

1 0

Chia sẻ

lợi nhuận đã nhận xét. Hãy nhớ rằng việc đăng bài thảo luận dưới 15 tuổi chỉ có vậy. Giấu kín. +15

Chuyển đổi mã python sang công cụ trực tuyến java

asutosh_1 -3 Áp phích dành cho người mới

1 năm trước

def findMaximumPath(mat)

hàng = cols = len(mat)

đếm_list = []

cho tôi trong phạm vi (hàng)

tổng = 0

mat_index = [hàng-1, cols-1]

curr_index = [0, tôi]

tổng = mat[curr_index[0]][curr_index[1]]

trong khi curr_index[0]. = rows-1 và curr_index[1]. = cols-1

nếu mat[curr_index[0]][curr_index[1]+1] > mat[curr_index[0]+1][curr_index[1]]

curr_index[1] = curr_index[1] + 1

khác

curr_index[0] = curr_index[0] + 1

summ += mat[curr_index[0]][curr_index[1]]

#print(str(curr_index) + " Tổng. " + str(tổng))

nếu curr_index[0]. = rows-1 và curr_index[1] == cols-1

cho tôi trong phạm vi(curr_index[0]+1, rows)

tổng += mat[i][cols-1]

#print(str(i) + " Sum1. " +str(tổng))

nếu curr_index[0] == rows-1 và curr_index[1]. = cols-1

cho tôi trong phạm vi(curr_index[1]+1, cols)

summ += mat[rows-1][i]

#print(str(i) + " Sum2. " +str(tổng))

đếm_list. nối thêm (tổng)

max_sum = max(count_list)

đếm = 0

cho phần tử trong count_list

nếu (phần tử == max_sum)

đếm+= 1

in (count_list)

print("Tổng tối đa. " + str(max_sum))

print("Số lần xuất hiện. " + str(đếm) + "\n")

mat1 = ([[3, 1, -2, 1, 1],

[-6, -1, 4, -1, -4],

[1, 1, 1, 1, 1],

[2, 2, 2, 2, 2],

[1, 1, 1, 1, 1]])

mat2 = ([[1, 1, 1],

[2, 2, 2],

[3, 3, 3]])

findMaximumPath(mat1)

findMaximumPath(mat2)

0 1

Chia sẻ

lợi nhuận đã nhận xét. Trễ 15 năm. Định dạng kém. Tại sao? -3

Chuyển đổi mã python sang công cụ trực tuyến java

COCO_ -3 Áp phích dành cho người mới

1 năm trước

nhập ngẫu nhiên
#Planet;Khoảng cách từ Mặt trời (tính bằng triệu km);Kích thước (Đường kính tính bằng km);Chu kỳ quỹ đạo (tính bằng ngày);Số lượng Mặt trăng;
planets = []
planets.append(["Mercury",57.9,4879,88,0])
hành tinh. append(["Venus",108. 2,12104,224. 7,0])
các hành tinh. append(["Trái đất",149. 6,12756,365. 2,1])
các hành tinh. append(["Mars",227. 9,6792,687,2])
hành tinh. append(["Jupiter",778. 6,142984,4331,67])
các hành tinh. append(["Saturn",1433. 5,120536,10747,62])
các hành tinh. append(["Uranus",2872. 5,51118,30589,27])
các hành tinh. append(["Neptune",4495. 1,49528,59800,14])
các hành tinh. append(["Pluto",5906. 4,2370,90560,5])

print("Thẻ của bạn. ")
số thẻ = ngẫu nhiên. randint(0,len(các hành tinh)-1)
print("---> Hành tinh. " + các hành tinh[cardNumber][0])
print("---> Khoảng cách từ Mặt trời. " + str(các hành tinh[cardNumber][1])+ " triệu km. ")
print("---> Đường kính. " + str(các hành tinh[cardNumber][2])+ " km. ")
print("---> Chu kỳ quỹ đạo. " + str(các hành tinh[cardNumber][3])+ " ngày. ")
print("---> Số mặt trăng. " + str(các hành tinh[số thẻ][4]))

0 2

Chia sẻ

lợi nhuận đã nhận xét. Một lần nữa, trễ 15 năm. Định dạng kém. Tại sao? -3

Chuyển đổi mã python sang công cụ trực tuyến java

mu_2 -3 Áp phích dành cho người mới

1 năm trước

defFlip(b).
return [[b[(N-1)-i][j]for j in range(N)]for i in range(N)]
.
return[[b[N-1)-j][i]for j in range(N)]for i in range(N)]
defRot180 .
return Rot90(Rot90(b))
defRot270(b).
return Rot180(Rot90(b))
defFlipRot90(b).
return Flip(Rot90(b))
defFlipRot180(b).
return Flip(Rot180(b))
defFlipRot270(b).
return Flip(Rot270(b))
def OutputAndProcess(b).
allsol toàn cầu
c=deepcopy(b)
eqclass=
(c,Rot90 . gia hạn([c])
allsol.extend([c])
if(qu=="Y") or(qu=="Y").
print("Giải pháp ",len(allsol),". ")
cho tôi trong phạm vi(N).
cho j trong phạm vi(N).
if c[i][j] ==1.
print('Q',end='')
if c[i][j] ==0.
print('-',end='')
if c[i][j] ==-1.
print('',end='')
print('',end='\n')
print .
print('',end='\n')
defClearThisWay(r,colQ,deltx,delty):
x =r + deltx
Y=colQ + delty
while(x>=0)and(y>=0 .
if b[x][y]==-1.
trả về 1
nếu b[x][y]==1.
trả về 0
x=x + deltx
y=y + deltx
trả về 1 .
defNoQueenAttacks(r,colQ):
return (ClearThisWay(r,colQ,-1,0)and ClearThisWay(r,colQ,0,-1)and ClearThisWay(r,colQ,-1,-1)and ClearThisWay( .
defLastPieceinColumn(colP):
i=N-1
while (i>=0).
if b[i][colP]. =0.
return b[i][colP]
i=i-1
return 0
def QueensAndPawns(r,c,p):
if(r==N)and(p==0).
outputAndProcess(b)
else.
cho colQ trong phạm vi(c,N).
if NoQueenAttack(r,colQ).
b[r][colQ]=1
if p>0.
đối với colP trong phạm vi(colQ+1,N-1).
ifLastPieceinColumn(colP) == 1.
b[r][colP] =-1
QueensAndPawns(r,colP+1,p-1)
b
QueensAndPawns(r+1,0,p)
b[r][colQ] = 0

N,b,qu,allsol toàn cầu
N=7
p=2
qu=input( . ")
b=[[0 for i in range(N)]for j in range(N)]
allsol=[]
QueensAndPawns(0,0,p)
qu=input("Hit Enter to end program:")

0 1

Chia sẻ

lợi nhuận đã nhận xét. Một lần nữa, trễ 15 năm. Định dạng kém. Tại sao -3

Chuyển đổi mã python sang công cụ trực tuyến java

JamesCherrill 4,667 Người đăng có giá trị nhất Người kiểm duyệt Người đăng nổi bật<

1 năm trước

Bạn chiếm quyền điều khiển một chuỗi 15 năm tuổi để đăng Python không có chú thích?
Và bạn muốn chúng tôi làm gì?

1 0

Chia sẻ

Chuyển đổi mã python sang công cụ trực tuyến java

toto_4 -3 Áp phích dành cho người mới

1 năm trước

defFlip(b).
return [[b[(N-1)-i][j]for j in range(N)]for i in range(N)]
.
return[[b[N-1)-j][i]for j in range(N)]for i in range(N)]
defRot180 .
return Rot90(Rot90(b))
defRot270(b).
return Rot180(Rot90(b))
defFlipRot90(b).
return Flip(Rot90(b))
defFlipRot180(b).
return Flip(Rot180(b))
defFlipRot270(b).
return Flip(Rot270(b))
def OutputAndProcess(b).
allsol toàn cầu
c=deepcopy(b)
eqclass=
(c,Rot90 . gia hạn([c])
allsol.extend([c])
if(qu=="Y") or(qu=="Y").
print("Giải pháp ",len(allsol),". ")
cho tôi trong phạm vi(N).
cho j trong phạm vi(N).
if c[i][j] ==1.
print('Q',end='')
if c[i][j] ==0.
print('-',end='')
if c[i][j] ==-1.
print('',end='')
print('',end='\n')
print .
print('',end='\n')
defClearThisWay(r,colQ,deltx,delty):
x =r + deltx
Y=colQ + delty
while(x>=0)and(y>=0 .
if b[x][y]==-1.
trả về 1
nếu b[x][y]==1.
trả về 0
x=x + deltx
y=y + deltx
trả về 1 .
defNoQueenAttacks(r,colQ):
return (ClearThisWay(r,colQ,-1,0)and ClearThisWay(r,colQ,0,-1)and ClearThisWay(r,colQ,-1,-1)and ClearThisWay( .
defLastPieceinColumn(colP):
i=N-1
while (i>=0).
if b[i][colP]. =0.
return b[i][colP]
i=i-1
return 0
def QueensAndPawns(r,c,p):
if(r==N)and(p==0).
outputAndProcess(b)
else.
cho colQ trong phạm vi(c,N).
if NoQueenAttack(r,colQ).
b[r][colQ]=1
if p>0.
đối với colP trong phạm vi(colQ+1,N-1).
ifLastPieceinColumn(colP) == 1.
b[r][colP] =-1
QueensAndPawns(r,colP+1,p-1)
b
QueensAndPawns(r+1,0,p)
b[r][colQ] = 0

N,b,qu,allsol toàn cầu
N=7
p=2
qu=input( . ")
b=[[0 for i in range(N)]for j in range(N)]
allsol=[]
QueensAndPawns(0,0,p)
qu=input("Hit Enter to end program:")

0 1

Chia sẻ

JamesCherrill đã nhận xét. Xúc phạm sự thiếu nỗ lực -3

Chuyển đổi mã python sang công cụ trực tuyến java

JamesCherrill 4,667 Người đăng có giá trị nhất Người kiểm duyệt Người đăng nổi bật<

1 năm trước

Không có gì giống như lặp lại cùng một sai lầm

Bạn chiếm quyền điều khiển một chuỗi 15 năm tuổi để đăng Python không có chú thích?
Và bạn muốn chúng tôi làm gì?

1 0

Chia sẻ

lợi nhuận đã nhận xét. Đây là một trường hợp tốt để đóng các cuộc thảo luận cũ. +15

Chuyển đổi mã python sang công cụ trực tuyến java

Md Shamshad 15 Áp phích dành cho người mới

1 năm trước

n = int(input())list1 = list(map(int,input(). split()))set1 = set(list1)set2=set(sorted(set1))#print(type(set1))set_bob = sorted(set1)#print(set2)set_3 = set()set_2 = set()set_rest . nếu tôi%3==0. bộ_3. thêm (i) cho tôi trong set2. nếu tôi%2==0. bộ_2. thêm(i)set_2_extra = set_3. giao lộ(set_2) set_2 = set_2. chênh lệch(set_2_extra)set_rest = set2. sự khác biệt (set_2. union(set_3))set_2 = đã sắp xếp(set_2)set_3 = đã sắp xếp(set_3)set_rest = đã sắp xếp(set_rest)set_alice = set_3+set_2+set_restalice = 0bob = 0tie = 0for i in range(len(set_alice)). if(set_alice[i]>set_bob[i]). alice+=1 elif(set_alice[i]