Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Info by dfs
//'main' method must be in a class 'Rextester'. //openjdk version '11.0.5' import java.util.*; import java.lang.*; class Rextester { public static void main(String args[]) { Scanner sc=new Scanner(System.in); String str=sc.nextLine(); int l=str.length(); int i; String str2= new String(""); LinkedList<Integer> a[]=new LinkedList[l]; for(i=0;i<l;i++) { char x=str.charAt(i); if( x=='N') str2+='0'; else str2+=x; } for(i=0;i<l;i++) a[i]=new LinkedList<>(); System.out.println(str2); for(i=0;i<(l/2);i++) { int tmp1,tmp2,tmp3; char zz=str2.charAt(i); tmp3=Integer.parseInt(String.valueOf(zz)); char xx=str2.charAt((2*i+1)); char yy=str2.charAt((2*i+2)); tmp1=Integer.parseInt(String.valueOf(xx)); tmp2=Integer.parseInt(String.valueOf(yy)); System.out.print("i---->"+tmp3+" is conneccted to "); System.out.print(tmp1+ " "); System.out.println(tmp2); a[tmp3].addFirst(tmp1); a[tmp1].addFirst(tmp3); a[tmp3].addFirst(tmp2); a[tmp2].addFirst(tmp3); } for ( i = 0; i <l ; i++) { if(a[i].size()>0) { System.out.print("Vertex " + i + " is connected to: "); for (int j = 0; j < a[i].size(); j++) { System.out.print(a[i].get(j) + " "); } System.out.println(); } } } }
run
|
edit
|
history
|
help
0
circleapp.java
Sorting array
Palindrome Number in Java
java274
preincrement
jb14 L
Problem: rstring
Crescente.java
Tree ZigZag Traversal
reservation vehicules