Horje
python to c++ transpiler Code Example
python to c++ transpiler
f = open("17.txt")
a = f.readlines()
a = list(map(int,a))

max = -1
count = 0
for i in range(len(a)-1):
    for j in range(i + 1, len(a)):
        if (a[i]%19==0 or a[j]%19==0) and (a[i] - a[j])%2==0:
            count= count + 1
            if a[i] + a[j] > max:
                max = a[i] + a[j]
print(count, max)
python to c++ transpiler
def swapList(newList):
	size = len(newList)
	
	
	temp = newList[0]
	newList[0] = newList[size - 1]
	newList[size - 1] = temp
	
	return newList
	

newList = [12, 35, 9, 56, 24]

print(swapList(newList))
python to c++ transpiler
test = int(input())
a = []
for i in range(test):
    S1 = input()
    S2 = input()
    X = input()
    a.append([S1,S2,X])

for i in a:
    count = 0
    for j in range(len(i[0])+1):
        if i[2].find(i[0][:j])==-1:
             break
        for k in range(len(i[1])+1):
            if i[2].find(i[0][:j]+i[1][:k])==-1:
                break
            else :
                count = count+1
    print(count)
            
python to c++ transpiler
def swapList(newList):
	size = len(newList)
	
	
	temp = newList[0]
	newList[0] = newList[size - 1]
	newList[size - 1] = temp
	
	return newList
	

newList = [12, 35, 9, 56, 24]

print(swapList(newList))
python to c++ transpiler
arr = list(input())
numbers = []
for i in range(len(arr)):
    if arr[i].isdigit():
        numbers.append(arr[i])
    else:
        pass
print(numbers
python to c++ transpiler
def find_zero_sum(list1,list2):
    for loop1 in range(len(list1)):
        for loop2 in range(len(list2)):
            if(list1[loop1] != 999 or list2[loop2] != 999):
                if(list1[loop1] + list2[loop2] == 0):
                    print('Required number in list1: ',list1[loop1])
                    print('Required number in list2: ',list2[loop2])
                    break
python to c++ transpiler
from mpi4py import MPI
from scipy import misc
import numpy as np
import math
comm = MPI.COMM_WORLD
size = comm.Get_size()
rank = comm.Get_rank()


newImage = []
kernel = np.array([
    [0, -1, 0],
    [-1, 4, -1],
    [0, -1, 0]
])
def multiplication(FinalImage):
    for i in range(start + 1, end + 1):
        inner_arr = []
        for j in range(1, width + 1):
            val= FinalImage[i - 1, j - 1] * kernel[0, 0] + FinalImage[i - 1, j] * kernel[0, 1] + \
                    FinalImage[i - 1, j + 1] * kernel[0, 2]
            val+= FinalImage[i, j - 1] * kernel[1, 0] + FinalImage[i, j] * kernel[1, 1] + FinalImage[
                i, j + 1] * kernel[1, 2]

            val+= FinalImage[i + 1, j - 1] * kernel[2, 0] + FinalImage[i + 1, j] * kernel[2, 1] + \
                     FinalImage[i + 1, j + 1] * kernel[2, 2]
            inner_arr.append(val)
        newImage.append(inner_arr)

if rank == 0:
      image= misc.imread('nn.png')
      num_OF_rows= image.shape[0]
      num_OF_columns= image.shape[1]

      for i in range (size-1):
          comm.send([num_OF_rows, num_OF_columns], dest=i+1 , tag=1)

      # tag 2 for gray scale
      GrayImage= []
      for i in range (size-1):
         comm.send(image , dest=i+1 , tag=2)

      for i in range (size-1):
          GrayImage+= comm.recv(source=i+1 , tag=2)

      misc.imsave("grayImage.png", GrayImage)



      # padding
      Paded_image= np.zeros((num_OF_rows + 2, num_OF_columns + 2))
      Paded_image[1:num_OF_rows + 1, 1:num_OF_columns + 1] = image[0:num_OF_rows  ,0:num_OF_columns, 0]



      # tag 3 for HPF
      for i in range ( size-1):
          comm.send(Paded_image, dest=i+1, tag=3)

      HPF_image= []
      for i in range (size-1):
          HPF_image+= comm.recv(source=i+1, tag=3)

      misc.imsave("output.png", HPF_image)
      print("OUTPUT IS DONE")


else:
      Image_dimensions= comm.recv(source=0, tag=1)
      height= Image_dimensions[0]
      width= Image_dimensions[1]

      num_rows= math.ceil(height / (size - 1))
      start= (num_rows * (rank - 1))
      end= start + num_rows

      #end of the image reached
      if end > height:
         end= height


      Colored_image = comm.recv(source=0, tag=2)

      #GRAY STEP
      new_img= []
      for i in range(start, end):
          inner_arr= []
          for j in range(width):
              value= Colored_image[i,j,0]
              inner_arr.append(value)
          new_img.append(inner_arr)
      comm.send(new_img, dest=0, tag=2)

      FinalImage= comm.recv(source=0, tag=3)

      multiplication(FinalImage)

      # Result
      new_img= []
      for i in range(len(newImage)):
        inner_arr= []
        for j in range(len(newImage[0])):
            #ideal_highpass(highpass+domainsample)
            #value=math.sqrt((newImage[i][j])*(newImage[i][j]))
            #highpass
            value = (newImage[i][j])
            inner_arr.append(value)
        new_img.append(inner_arr)
      comm.send(new_img, dest=0, tag=3)
python to c++ transpiler
def out_write(lst):
    for k in range(len(lst)):
        if len(lst[k])>0:
            # out.write("\n")
            for i in lst[k]:
                out.write(str(k+2)+' ')
                for j in i:
                    out.write(str(j)+' ')
                out.write("\n")

f=open("e_many_teams.in",'r')
open("e_many_teams.out","w").close()
out=open("e_many_teams.out",'a')

l=[]
base=[]
ingredients=set()
pizza_list_distinct={}
for i in f.readlines():
    t=i[:len(i)]
    pizza=t.split()
    if len(l)==0:
        base=pizza.copy()
    l.append(pizza)
length=len(l)
del l[0]

for i in range (len(l)):
    pizza_list_distinct[i]=set(l[i][1:])


for j in range(len(base)):
    base[j]=int(base[j])
total_pizzas=base[0]
total_participants=(base[1]*2)+(base[2]*3)+(base[3]*4)
diff=total_participants-total_pizzas
if diff<0:
    diff=total_participants

t2=[]
t3=[]
t4=[]


counter=diff
if total_participants>total_pizzas:
    while diff>0:
        if diff>=4 and base[3]>0:
            base[3]-=1
            diff-=4
        elif diff>=3 and base[2]>0:
            base[2]-=1
            diff-=3
        elif diff>=1 and base[1]>0:
            base[1]-=1
            diff-=2

counter=base[1]*2+base[2]*3+base[3]*4

count=0
counter1=counter

all_pizzas=[]
for j in l:
    t=set(j[1:])
    all_pizzas.append(t)


while counter>0:
    if base[3]>0:
        temp=set()
        i=1
        val=[]
        while len(val)!=4:
            for key,value in pizza_list_distinct.items() :
                if len(val)==0:
                    if all_pizzas[0]==value:
                        temp=temp.union(pizza_list_distinct[key])
                        val.append(key)
                        del pizza_list_distinct[key]
                        del all_pizzas[0]
                        counter-=1
                        break
                else:
                    if len(temp.union(value)) >= (len(temp) + len(value) -1):
                        temp=temp.union(pizza_list_distinct[key])
                        val.append(key)
                        del pizza_list_distinct[key]
                        all_pizzas.remove(value)
                        counter-=1
                        break
        base[3]-=1
        t4.append(val)
        val=[]

    if base[2]>0:
        temp=set()
        i=1
        val=[]
        while len(val)!=3:
            for key,value in pizza_list_distinct.items() :
                if len(val)==0:
                    if all_pizzas[0]==value:
                        temp=temp.union(pizza_list_distinct[key])
                        val.append(key)
                        del pizza_list_distinct[key]
                        del all_pizzas[0]
                        counter-=1
                        break
                else:
                    if len(temp.union(value)) >= (len(temp) + len(value) -1):
                        temp=temp.union(pizza_list_distinct[key])
                        val.append(key)
                        del pizza_list_distinct[key]
                        all_pizzas.remove(value)
                        counter-=1
                        break
        base[2]-=1
        t3.append(val)
        val=[]

    if base[1]>0:
        temp=set()
        i=1
        val=[]
        while len(val)!=2:
            for key,value in pizza_list_distinct.items() :
                if len(val)==0:
                    if all_pizzas[0]==value:
                        temp=temp.union(pizza_list_distinct[key])
                        val.append(key)
                        del pizza_list_distinct[key]
                        del all_pizzas[0]
                        counter-=1
                        break
                else:
                    if len(temp.union(value)) >= (len(temp) + len(value) -1):
                        temp=temp.union(pizza_list_distinct[key])
                        val.append(key)
                        del pizza_list_distinct[key]
                        all_pizzas.remove(value)
                        counter-=1
                        break
        base[1]-=1
        t2.append(val)
        val=[]
    
    else:
        continue

count=(len(t2)+len(t3)+len(t4))

output=[t2,t3,t4]
out.write(str(count))
out.write("\n")
out_write(output)
python to c++ transpiler
from tkinter import*


def btnClick(numbers):
    global operator
    operator = operator + str(numbers)
    text_Input.set(operator)


def btnClearDisplay() :
    global operator
    operator=""
    text_Input.set("")


def btnEqualsInput() :
    global operator
    sumup=str(eval(operator))
    text_Input.set(sumup)
    operator=""


cal = Tk()
cal.title("Calculator")
operator = ""
text_Input = StringVar()

txtDisplay = Entry(cal, font=("arial", 20, "bold"), textvariable=text_Input, bd=30, insertwidth=4,
                   bg="black", justify="right", fg="white").grid(columnspan=4)

btn7 = Button(cal, padx=16, pady=10,  bd=8, fg="black", font=("arial", 20, "bold"),
              text="7", command=lambda: btnClick(7)).grid(row=1, column=0)

btn8 = Button(cal, padx=16, pady=10,  bd=8, fg="black", font=("arial", 20, "bold"),
              text="8", command=lambda: btnClick(8)).grid(row=1, column=1)

btn9 = Button(cal, padx=16, pady=10,  bd=8, fg="black", font=("arial", 20, "bold"),
              text="9", command=lambda: btnClick(9)).grid(row=1, column=2)

Addition = Button(cal, padx=16, pady=10,  bd=8, fg="black", font=("arial", 20, "bold"),
                  text="+", command=lambda: btnClick("+")).grid(row=1, column=3)

btn4 = Button(cal, padx=16, pady=10,  bd=8, fg="black", font=("arial", 20, "bold"),
              text="4", command=lambda: btnClick(4)).grid(row=2, column=0)

btn5 = Button(cal, padx=16, pady=10,  bd=8, fg="black", font=("arial", 20, "bold"),
              text="5", command=lambda: btnClick(5)).grid(row=2, column=1)

btn6 = Button(cal, padx=16, pady=10,  bd=8, fg="black", font=("arial", 20, "bold"),
              text="6", command=lambda: btnClick(6)).grid(row=2, column=2)

Subtraction = Button(cal, padx=16, pady=10,  bd=8, fg="black", font=("arial", 20, "bold"),
                     text="-", command=lambda: btnClick("-")).grid(row=2, column=3)

btn1 = Button(cal, padx=16, pady=10,  bd=8, fg="black", font=("arial", 20, "bold"),
              text="1", command=lambda: btnClick(1)).grid(row=3, column=0)

btn2 = Button(cal, padx=16, pady=10,  bd=8, fg="black", font=("arial", 20, "bold"),
              text="2", command=lambda: btnClick(2)).grid(row=3, column=1)

btn3 = Button(cal, padx=16, pady=10,  bd=8, fg="black", font=("arial", 20, "bold"),
              text="3", command=lambda: btnClick(3)).grid(row=3, column=2)

Multiplication = Button(cal, padx=16, pady=10,  bd=8, fg="black", font=("arial", 20, "bold"),
                        text="*", command=lambda: btnClick("*")).grid(row=3, column=3)

btn0 = Button(cal, padx=16, pady=10, bd=8, fg="black", font=("arial", 20, "bold"),
              text="0", command=lambda: btnClick(0)).grid(row=4, column=0)

btnClear = Button(cal, padx=16, pady=10, bd=8, fg="black", font=("arial", 20, "bold"),
                  text="C", command=btnClearDisplay).grid(row=4, column=1)

btnEquals = Button(cal, padx=16, pady=10, bd=8, fg="black", font=("arial", 20, "bold"),
                   text="=", command=btnEqualsInput).grid(row=4, column=2)

Division = Button(cal, padx=16, pady=10, bd=8, fg="black", font=("arial", 20, "bold"),
                  text="/", command=lambda: btnClick("/")).grid(row=4, column=3)


cal.mainloop()
python to c++ transpiler
def fitness(cand):
    candidato=[]   
    for ia in range (75):
        soma1=0
        soma2=0
        soma3=0
        ib=cand*12 #endereço do individuo dentro da matriz B
        for j in range (nv): 
            soma1 = out[ia][ib+j] + soma1 #soma elementos do cluster 1
            soma2 = out[ia][ib+j+nv] + soma2 #soma elementos do cluster 2
            soma3 = out[ia][ib+nv*2] + soma3 #soma elementos do cluster 3
                        
        candidato.append(min(np.sqrt(soma1),np.sqrt(soma2),np.sqrt(soma3)))
        
    return np.sum(candidato)




Cpp

Related
++m in c Code Example ++m in c Code Example
print the elements of the array without using the [] notation in c++ Code Example print the elements of the array without using the [] notation in c++ Code Example
Function to calculate compound interest in C++ Code Example Function to calculate compound interest in C++ Code Example
C++ to specify size and value Code Example C++ to specify size and value Code Example
geekforgeeks stacks Code Example geekforgeeks stacks Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
8