Answers for "convert code python to java"

0

convert code python to java

#include <bits/stdc++.h>
using namespace std;
 
int main()
{
  int m,ans=INT_MAX,I=-1,J=-1;
  cin>>m;
  vector<vector<int>> mat(m,vector<int>());
  cin.ignore();
  for(int i=0;i<m;i++)
  {
    string s;
    getline(cin,s);
    istringstream ss(s);
    while(ss)
    {
      string w;
      ss>>w;
      if(w=="") break;
      mat[i].push_back(stoi(w));
    }
  }
  int n=mat[0].size();
  vector<vector<int>> Ans1(m,vector<int>(n,1));
  vector<vector<int>> Ans2(m,vector<int>(n,1));
  vector<vector<int>> Ans3(m,vector<int>(n,1));
  vector<vector<int>> Ans4(m,vector<int>(n,1));
 
  for(int i=0;i<m-1;i++)
  for(int j=0;j<mat[i].size();j++)
  if(mat[i][j]==mat[i+1][j])
    Ans1[i+1][j]=Ans1[i][j]+1;
  
  for(int i=0;i<m;i++)
  for(int j=0;j<mat[i].size() -1;j++)
  if(mat[i][j]==mat[i][j+1])
    Ans2[i][j+1]=Ans2[i][j]+1;
  
  for(int i=0;i<m-1;i++)
  for(int j=0;j<mat[i].size()-1;j++)
  if(mat[i][j]==mat[i+1][j+1])
    Ans3[i+1][j+1]=Ans3[i][j]+1;
 
  for(int i=0;i<m-1;i++)
  for(int j=1;j<mat[i].size();j++)
  if(mat[i][j]==mat[i+1][j-1])
    Ans4[i+1][j-1]=Ans4[i][j]+1;
  
  for(int i=0;i<m;i++)
  for(int j=0;j<mat[i].size();j++)
  {
    if(Ans1[i][j]>=4 && ans>mat[i][j])
    {ans=mat[i][j];I=i;J=j;}
    if(Ans2[i][j]>=4 && ans>mat[i][j])
    {ans=mat[i][j];I=i;J=j;}
    if(Ans3[i][j]>=4 && ans>mat[i][j])
    {ans=mat[i][j];I=i;J=j;}
    if(Ans3[i][j]>=4 && ans>mat[i][j])
    {ans=mat[i][j];I=i;J=j;}
  }
  if(I==-1)cout<<-1;
  else cout<<ans<<endl;
  
}
Posted by: Guest on April-18-2021
0

convert code python to java

def tipo_melenudos(lista):
    lista_nueva=[]
    for i in range(len(lista)):
        if lista[i] not in lista_nueva:
            lista_nueva.append(lista[i])
    return lista_nueva
Posted by: Guest on August-23-2021
0

convert code python to java

def BitmapHoles(strArr):
    bitmap = {}
    for i in range(len(strArr)):
        for j in range(len(strArr[i])):
            bitmap[(i,j)] = int(strArr[i][j])
    
    hole_count = 0
    hole = set()
    checked = set()
    flag = True
    
    for i in range(len(strArr)):
        for j in range(len(strArr[i])):
            stack = [(i,j)]
            while stack:
                coords = stack.pop()
                if coords not in checked:
                    checked.add(coords)
                    if bitmap[coords] == 0 and coords not in hole:
                        hole.add(coords)
                        if flag == True:
                            hole_count += 1
                            flag = False
                        if coords[0] - 1 >= 0 and (coords[0]-1,coords[1]) not in checked:
                            stack.append((coords[0]-1,coords[1]))
                        if coords[0] + 1 < len(strArr) and (coords[0]+1,coords[1]) not in checked:
                            stack.append((coords[0]+1,coords[1]))
                        if coords[1] - 1 >= 0 and (coords[0],coords[1]-1) not in checked:
                            stack.append((coords[0],coords[1]-1))
                        if coords[1] + 1 < len(strArr[coords[0]]) and (coords[0],coords[1]+1) not in checked:
                            stack.append((coords[0],coords[1]+1))
            flag = True
            
    return hole_count
Posted by: Guest on May-01-2021
0

convert code python to java

n = int(input())
output = []
strings = []
for _ in range(n):
  strings.append(input().strip())
q = int(input())
for _ in range(q):
  L,R,K = map(int, input().split())
  s = ""
  for __ in range(L-1,R):
      s += strings[__]
  output.append(s[K-1])
print(*sorted(output),sep='\n')
Posted by: Guest on June-26-2021
0

convert code python to java

def BitmapHoles(strArr):
    bitmap = {}
    for i in range(len(strArr)):
        for j in range(len(strArr[i])):
            bitmap[(i,j)] = int(strArr[i][j])
    
    hole_count = 0
    hole = set()
    checked = set()
    flag = True
    
    for i in range(len(strArr)):
        for j in range(len(strArr[i])):
            stack = [(i,j)]
            while stack:
                coords = stack.pop()
                if coords not in checked:
                    checked.add(coords)
                    if bitmap[coords] == 0 and coords not in hole:
                        hole.add(coords)
                        if flag == True:
                            hole_count += 1
                            flag = False
                        if coords[0] - 1 >= 0 and (coords[0]-1,coords[1]) not in checked:
                            stack.append((coords[0]-1,coords[1]))
                        if coords[0] + 1 < len(strArr) and (coords[0]+1,coords[1]) not in checked:
                            stack.append((coords[0]+1,coords[1]))
                        if coords[1] - 1 >= 0 and (coords[0],coords[1]-1) not in checked:
                            stack.append((coords[0],coords[1]-1))
                        if coords[1] + 1 < len(strArr[coords[0]]) and (coords[0],coords[1]+1) not in checked:
                            stack.append((coords[0],coords[1]+1))
            flag = True
            
    return hole_count
Posted by: Guest on May-01-2021
0

convert code python to java

def tipo_melenudos(lista):
    lista_nueva=[]
    for i in range(len(lista)):
        if lista[i] not in lista_nueva:
            lista_nueva.append(lista[i])
    return lista_nueva
Posted by: Guest on August-23-2021
0

convert code python to java

s=input()
l=[]
s1='aeiou'
sum1=0
def snm(sum1):
    t=0
    while(sum1>0 or t>9):
        if(sum1==0):
            sum1=t
            t=0
        t=t+sum1%10
        sum1=sum1//10
    return t
    
for i in range(len(s)):
    if s[i] in s1:
        l.append(i)
for j in range(len(l)):
    k=l[j]*5
    sum1=0
    for h in range(1,k+1,2):
        sum1=sum1+h
    print(snm(sum1))
Posted by: Guest on April-18-2021

Code answers related to "convert code python to java"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language