Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* *****************************************************************************
- * Name: maxpigreco
- ******************************************************************************* */
- public class FiltraConsecutivi {
- public static void main(String[] args) {
- // Caso senza input
- if (StdIn.isEmpty()) {
- StdOut.println("Nessun valore inserito");
- return;
- }
- int x = StdIn.readInt();
- String filter = Integer.toString(x);
- while (!StdIn.isEmpty()) {
- int y = StdIn.readInt();
- if (y != x) {
- filter += " " + Integer.toString(y);
- x = y;
- }
- }
- StdOut.print(filter);
- }
- }
- /*
- input: 1 2 2 1 5 1 1 7 7 7 7 1 1 1 1 1 1 1 1 1 CTRL+D (one per line)
- output: 1 2 1 5 1 7 1
- */
Add Comment
Please, Sign In to add comment