java-1006 Change the format to output integers (15)


1006 Change format to output integer (15) (15 points)

Let's use the letter B for "hundred", the letter S for "ten", and "12...n" for the ones digit n (<10), and change the format to output any positive integer up to 3 digits. For example, 234 should be output as BBSSS1234 because it has 2 "hundreds", 3 "tens", and a 4 for the ones.

Input format: Each test input contains 1 test case, giving a positive integer n (<1000).

Output format: The output of each test case occupies one line, and outputs n in the specified format.

Input sample 1:

234

Sample output 1:

BBSSS1234

Input sample 2:

23

Sample output 2:

SS123

 consists of several steps

    1. Data acquisition

    2. Data processing

    3. Big Process

1. Data acquisition:

public static String getData() throws IOException {
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
        return bufferedReader.readLine();
    }

 2. Data processing

public static void getX(char c, StringBuffer stringBuffer, String X) {
        int size = c - 48;
        for ( ; size > 0 ; size --) {
            stringBuffer.append(X);
        }
    }

    public static void get123(char c, StringBuffer stringBuffer) {
        int size = c - 48;
        for (int i = 1 ; i <= size ; i ++) {
            stringBuffer.append(i);
        }
    }

There are two cases, the former deals with hundreds and tens, and the latter deals with ones.

3. Overall process

public static void main() throws Exception {
        String target = getData();
        StringBuffer result = new StringBuffer();
        switch (target.length()) {
            case 1:
                get123(target.charAt(0), result);
                System.out.print(result.toString());
                break;
            case 2:
                getX(target.charAt(0), result, "S");
                get123(target.charAt(1), result);
                System.out.print(result.toString());
                break;
            case 3:
                getX(target.charAt(0), result, "B");
                getX(target.charAt(1), result, "S");
                get123(target.charAt(2), result);
                System.out.print(result.toString());
                break;
        }
    }

transfer:

public static void main(String[] args) throws Exception {
        main();
    }

Related


Powershell - change output format

shi How to change the appearance of the output produced by the code: $apps = Import-CSV apps.csv $computers = Import-CSV compobj.csv foreach($computer in $computers) { $computerLob = $computer.lob $lobApps = $apps | ? {$_.lob -eq $computerLob }

Change the output format of strings

username i have a string string str = "a_b_c_ _ _abc_ _ _ _abcd"; Now, str must be converted to a string in the following format: [a][b][c][_ _abc][_ _ _abcd] How can this be done? frightened Kind of unpleasant, but you should get the idea. public static voi

Change the output format of Java's outputable XML elements

microphone I am using Java's jaxb to create XML files from Java objects. The problem I'm facing is the exact opposite of what is stated here: LinqToXml does not handle processable elements as expected In short: I want to properly describe members that are null

Change the output format of Java's outputable XML elements

microphone I am using Java's jaxb to create XML files from Java objects. The problem I'm facing is the exact opposite of what is stated here: LinqToXml does not handle processable elements as expected In short: I want to properly describe members that are null

Output of comma separated integers in Java

luke109 I have to write a program to find the prime numbers between two numbers entered by the user. The only problem I have is that the output has an extra comma, more than needed. How would I go about solving this problem? import java.util.Scanner; public c

Output of comma separated integers in Java

luke109 I have to write a program to find the prime numbers between two numbers entered by the user. The only problem I have is that the output has an extra comma, more than needed. How would I go about solving this problem? import java.util.Scanner; public c

Output of comma separated integers in Java

luke109 I have to write a program to find the prime numbers between two numbers entered by the user. The only problem I have is that the output has an extra comma, more than needed. How would I go about solving this problem? import java.util.Scanner; public c

Output of comma separated integers in Java

luke109 I have to write a program to find the prime numbers between two numbers entered by the user. The only problem I have is that the output has an extra comma, more than needed. How would I go about solving this problem? import java.util.Scanner; public c

Format integers using Java string format

I have a headache: I was wondering if it is possible to use String.format method in Java to give an integer before zero? E.g: 1 will become 001 2 will become 002 ... 11 will become 011 12 will become 012 ... 526 will remain 526 ... Currently, I have tried the

Format integers using Java string format

I have a headache: I'm wondering if it's possible to give an integer before zero using the String.format method in Java? E.g: 1 will become 001 2 will become 002 ... 11 will become 011 12 will become 012 ... 526 will remain 526 ... Currently, I have tried the

Format integers using Java string format

I have headache: I was wondering if it is possible to use String.format method in Java to give an integer before zero? E.g: 1 will become 001 2 will become 002 ... 11 will become 011 12 will become 012 ... 526 will remain 526 ... Currently, I have tried the fo

Change the output format of chr to hex

Akonsu Suppose I have print [chr 0x49, chr 0x9f] which output "I\159" printHow can I use hexadecimal numbers when printing characters that must appear as escape sequences ? This way my output is: "I\x9f" Eric The short answer is that you can't change it. pr

Change output format of split() in R

compound biological inhibitor Suppose I have the following split: x <- 1:5 K <- 2 y <- 5 split(sample(x), sample(1:K, y, replace = TRUE)) $`1` [1] 3 $`2` [1] 5 1 2 4 Is there a way to put the above form [, 1] [, 2] [1, ] 3 5 [2, ] 1

Change the format of the log output log

Jenny Hilton: I use go logrus and I need to change the format of the output message, but I have tried several attempts without success What I need is to format with logrus formatter [error]: datetime - message What I have tried without success is logger := &l

How to change date output format

Mazlin I am developing a system about allowances in PHP, MySQL, which should calculate the last date an employee will receive allowances . Here is the javascript I use to calculate the last date. The output of the following code is 15-7-2015 . I hope it's July

Change the output format of print numbers

Windler Here is the relevant script: window.onload = function calcPreco() { for(const cloud of Array.from(document.getElementsByName("cloud"))) { fetch("_config/buscar_valor.php?id="+cloud.getAttribute("cloudid")+"&periodicidade=monthly") .then(res =>

How to change the format of JSON output?

username I have PHP code that fetches data from a table in a mysql database and displays that data in JSON format. Here is my code: <?php include ("config/config.php"); //build query $query = "SELECT ProductID, Name, Price, Type, cat FROM store ORDER B

How to change the format of .describe() output?

woodpecker I put in .describe()a dataframe and the output doesn't look good. I want the output to show integers instead of simplifying with exponents. enter: df["A"].describe() The output is as follows: count 6.000000e+01 mean 7.123568e+04 std 2.1

Change the output format of chr to hex

Akonsu Suppose I have print [chr 0x49, chr 0x9f] which output "I\159" printHow can I use hexadecimal numbers when printing characters that must appear as escape sequences ? This way my output is: "I\x9f" Eric The short answer is that you can't change it. pr

Change format JSON output in file?

Pascal I have the next PHP code that makes me a JSON file with data from an SQL table: <?php $mysqli = new mysqli('localhost','root','xxxx','xxxx'); $myArray = array(); $result = $mysqli->query("SELECT CONCAT(Datum , ' ', Tijd) as Datum, KleurL FROM metingen o

Change output format of split() in R

compound biological inhibitor Suppose I have the following split: x <- 1:5 K <- 2 y <- 5 split(sample(x), sample(1:K, y, replace = TRUE)) $`1` [1] 3 $`2` [1] 5 1 2 4 Is there a way to put the above form [, 1] [, 2] [1, ] 3 5 [2, ] 1

Change output format of split() in R

compound biological inhibitor Suppose I have the following split: x <- 1:5 K <- 2 y <- 5 split(sample(x), sample(1:K, y, replace = TRUE)) $`1` [1] 3 $`2` [1] 5 1 2 4 Is there a way to put the above form [, 1] [, 2] [1, ] 3 5 [2, ] 1

Change output format of split() in R

compound biological inhibitor Suppose I have the following split: x <- 1:5 K <- 2 y <- 5 split(sample(x), sample(1:K, y, replace = TRUE)) $`1` [1] 3 $`2` [1] 5 1 2 4 Is there a way to put the above form [, 1] [, 2] [1, ] 3 5 [2, ] 1

How to change objdump output format?

Area Hi I am using this book to learn c compiler. https://www.sigbus.info/compilerbook I want to display the same results as shown in the book. what should I do? I think I need to change the version of gcc, objdump or options. The book says it is also possible

How to change the format of .describe() output?

woodpecker I put in .describe()a dataframe and the output doesn't look good. I want the output to show integers instead of simplifying with exponents. enter: df["A"].describe() The output is as follows: count 6.000000e+01 mean 7.123568e+04 std 2.1