Sie sind auf Seite 1von 4

CLASE 6 (30-08-18)

PROGRA 4

se puede resolver usando cola de estructura

import java.io.BufferedReader;

import java.io.IOException;

import java.io.InputStreamReader;

import java.io.PrintWriter;

import java.util.ArrayList;

import java.util.Iterator;

import java.util.List;

public class URI1110ThrowingCardsAway {

static BufferedReader in = new BufferedReader(new


InputStreamReader(System.in));

static PrintWriter out = new PrintWriter(System.out);

public static void main(String[] args) throws IOException {

String l, removed;

int n, base, number;

while (!(l = in.readLine()).equals("0")) {

n = Integer.parseInt(l);

if (n == 1) {

out.println("Discarded cards:");

out.println(1);

} else {

base = 1;

List<Integer> cards = new ArrayList<>();


for (int i = 1; i <= n; i++) {

cards.add(i);

base = 2;

boolean f = true;

removed = "";

while (cards.size() > 1) {

for (Iterator<Integer> iterator = cards.iterator();


iterator.hasNext();) {

number = iterator.next();

if (base == 2) {

base = 0;

removed += number + ", ";

iterator.remove();

base++;

out.println("Discarded cards: " + removed.substring(0,


removed.length() - 2));

out.println("Remaining card: " + cards.get(0));

out.close();

------------------------------------------------

import java.io.BufferedReader;

import java.io.IOException;

import java.io.InputStreamReader;
import java.io.PrintWriter;

import java.util.Arrays;

import java.util.Comparator;

/**

* See

* <a href="https://www.urionlinejudge.com.br/judge/en/problems/view/1244">Sort

* by length</a>

* @author Brian Yeicol Restrepo Tangarife

*/

public class URI1244SortByLength {

static BufferedReader in = new BufferedReader(new


InputStreamReader(System.in));

static PrintWriter out = new PrintWriter(System.out);

public static void main(String[] args) throws IOException {

int N = readInt();

String[] P;

while (N-- > 0) {

P = read().split("\\s");

Arrays.sort(P, new Comparator<String>() {

@Override

public int compare(String s1, String s2) {

return s2.length() - s1.length();

});

for (int i = 0; i < P.length; i++) {

out.print(P[i]);
out.print(i != P.length - 1 ? " " : "\n");

out.close();

private static String read() throws IOException {

return in.readLine();

private static int readInt() throws IOException {

return Integer.parseInt(in.readLine());

Das könnte Ihnen auch gefallen