In: Computer Science
Convert this pseudo code
program into sentences.
import java.util.ArrayList;
import java.util.Collections;
class Bulgarian
{
public static void main(String[] args)
{
max_cards=45;
arr->new ArraryList
col=1;
card=0;
left=max_cards;
do{
col->random
number
row->new
ArrayList;
for i=0 to
i<col
{
card++
add card into row
}
add row into
arr
left=max_cards-card;
}while(card<max_cards);
finish->false
while(!finish)
{
for i=0 to
arr.size()
remove one card from each row
add row into
arr
size->new
ArrayList;
for i=0 to
i<arr.size()
add arr[i] into size
sort(size)
for i=1 to
size.size()
if ith element is equals to (i-1)+1
finish->true
else
finish->false
for i=0 to
i<arr.size()
print->arr elements
}
}
}
Please find the answer below.
Please do comments in case of any issue. Also, don't forget to rate
the question. Thank You So Much.
Bulgarian.java
package staticclasses;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Random;
public class Bulgarian
{
public static void main(String[] args)
{
int max_cards=45;
ArrayList<ArrayList<Integer>> arr = new
ArrayList<>();
int col=1;
int card=0;
int left=max_cards;
Random rand = new Random();
do{
col = rand.nextInt(max_cards);
ArrayList<Integer> row = new
ArrayList<>();
for(int i=0;i<col;i++)
{
card++;
row.add(card);
}
arr.add(row);
left=max_cards-card;
}while(card<max_cards);
boolean finish=false;
while(!finish)
{
for(int i=0;i<arr.size();i++) {
arr.get(i).remove(0);
arr.add(arr.get(i));
}
ArrayList<ArrayList<Integer>> size =new
ArrayList<>();
for(int i=0;i<arr.size();i++)
size.add(arr.get(i));
sort(size);
for(int i=1;i<size.size();i++)
if (size.get(i)==size.get((i-1)+1))
finish=true;
else
finish=false;
for(int i=0;i<arr.size();i++)
System.out.println(arr.get(i));
}
}
}