python to java convert online code example

Example 1: python to java converter

try jython, Refer: https://www.jython.org

Example 2: python to java convert online

#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;
  
}