Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.io.*;
- import java.util.ArrayList;
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) throws IOException {
- Scanner scan = new Scanner(new FileReader("input.txt"));
- String s = scan.nextLine();
- ArrayList<String> digit = new ArrayList<String>();
- ArrayList<String> words = new ArrayList<String>();
- ArrayList<Boolean> dot_or_not_dot = new ArrayList<Boolean>();
- String str = new String();
- for (int i = 0; i < s.length(); ) {
- if(s.charAt(i) == '.')
- {
- dot_or_not_dot.add(true);
- }
- else
- {
- if (s.charAt(i) >= '0' && s.charAt(i)<='9') {
- str = "";
- while (i < s.length() && s.charAt(i) >= '0' && s.charAt(i)<='9') {
- str += s.charAt(i);
- i++;
- }
- digit.add(str);
- i += str.length();
- dot_or_not_dot.add(false);
- } else {
- int pos = i;
- str = "";
- while (i < s.length() && s.charAt(i) >= 'a' && s.charAt(i)<='z') {
- str += s.charAt(pos);
- pos++;
- }
- words.add(str);
- i += str.length();
- dot_or_not_dot.add(false);
- }
- }
- }
- int w = 0, d = 0;
- for (int i = 0; i < dot_or_not_dot.size(); i++)
- {
- if(dot_or_not_dot.get(i) == true)
- {
- System.out.print(".");
- }
- else
- {
- if (d < digit.size())
- {
- System.out.print(digit.get(d));
- d++;
- }
- else
- {
- System.out.print(words.get(w));
- w++;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement