| |

VerySource

 Forgot password?
 Register
Search
Author: daike1017

A java written question, thought it was very simple, but I didn't write it right for a long time! Please prawn give a c

  [Copy link]

0

Threads

23

Posts

17.00

Credits

Newbie

Rank: 1

Credits
17.00

 China

Post time: 2020-4-24 09:45:01
| Show all posts
C:\Documents and Settings\Administrator\Desktop> java a
120100101
One hundred and one hundred and one hundred and one hundred and one hundred and one hundred and one hundred and one
1
one
223
Two hundred and twenty-three
102
One hundred and two
1000
One thousand
1263
One thousand two hundred and thirty-three
123021
One ten two thousand thirty thousand two hundred eleven
100001
One hundred and one
Reply

Use magic Report

0

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-4-25 15:30:01
| Show all posts
There are standard algorithms on the Internet
Reply

Use magic Report

0

Threads

23

Posts

17.00

Credits

Newbie

Rank: 1

Credits
17.00

 China

Post time: 2020-4-25 18:30:02
| Show all posts
I found my little mistake, that's right
import java.io. *;


public class a
{
   public static void main (String [] args)
   {
     String s = new String ();
     BufferedReader br = new BufferedReader (new InputStreamReader (System.in));
     
     while (true)
     {
        try {s = br.readLine ();} catch (Exception e) {}
       Convert c = new Convert (s.toCharArray ());
       System.out.println (c);
     }
   }
}
class Convert
{
  final String [] str1 = {"", "Ten", "Hundred", "Thousand"};
  final String [] str2 = {"100 million", "10,000"};
  final String [] number = {"", "One", "Two", "Three", "Wu", "Wu", "Lu", "柒", "捌", "Jiu"};
  char [] num_char;
  StringBuffer sb = new StringBuffer ();
  int last;

  public Convert (char [] num)
  {
    num_char = num;
  }
  public String toString ()
  {
    last = num_char.length% 4;
    int pos = 0;
    add (sb, new String (num_char, 0, last));
    pos + = last;
    for (int i = (int) (num_char.length / 4); i> 0; i--)
    {
      if (i% 2 == 0) sb.append (str2 [0]);
      else sb.append (str2 [1]);
      add (sb, new String (num_char, pos, 4));
      pos + = 4;
    }
    if (last == 0) sb.deleteCharAt (0);
    return sb.toString ();
  }
  private void add (StringBuffer sb, String temp)
  {
    char [] temp2 = temp.toCharArray ();
    int length = temp.length ();
    for (int i = 0; i <length; i ++)
    {
      if (temp2 [i] == '0')
        if (sb.lastIndexOf ("zero")! = sb.length ()-1&&last! = 0) sb.append ("zero"); else;
      else
      {
        sb.append (number [temp2 [i]-'0']);
        sb.append (str1 [length-i-1]);
      }
    }
    try {
      if (sb.lastIndexOf ("zero") == sb.length ()-1) sb.deleteCharAt (sb.lastIndexOf ("zero"));
    } catch (Exception e) {}
  }
}

The result is this:
120100101
One hundred and one hundred and one hundred and one hundred and one hundred and one hundred and one hundred and one
20100101
Two thousand one hundred one hundred one hundred one hundred one
1234567894564513213
One hundred two hundred and thirty-three hundred thousand and one hundred thousand and ten thousand and ten thousand and ninety thousand and one hundred and ten thousand and one hundred and ten thousand and one hundred and ten thousand and one hundred and ten thousand and three thousand and two hundred and one hundred and ten thousand
121202013210301005401650540321013
One hundred and two hundred one hundred one hundred and two hundred thousand two hundred and ten thousand one hundred and three hundred three hundred two hundred ten thousand three hundred and ten billion
Billion thousand three hundred and twenty one thousand one hundred and ten thousand one hundred and thirteen
2121254548545
One hundred one thousand one hundred one two hundred one hundred two hundred million one hundred thousand one hundred thousand one hundred thousand one hundred thousand one hundred thousand one hundred thousand one hundred
1
one
123
One hundred two thirteen
100
One hundred
Reply

Use magic Report

0

Threads

23

Posts

17.00

Credits

Newbie

Rank: 1

Credits
17.00

 China

Post time: 2020-4-25 19:45:01
| Show all posts
There is still a small mistake, forget it, I will not change it, ha ha.
Reply

Use magic Report

2

Threads

6

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

 Author| Post time: 2020-5-5 16:15:01
| Show all posts
Let me verify
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-5-9 09:15:01
| Show all posts
I think that I am impeccable, I would like to be tested by experts.
Inspired bynanase, I would like to express my gratitude and would like to share ideas with you.

public class RMBConvert {
private static String [] faceVal = new String [] {"zero", "one", "two", "three", "really",
"Wu", "Lu", "Qi", "捌", "Jiu"};

private static String [] level = new String [] {"round", "pick up", "bai", "qian", "wan", "billion"};

public static void main (String [] arg) {
StringBuffer sb = new StringBuffer ();
try {
BufferedReader in = new BufferedReader (new InputStreamReader (
System.in));
String s1 = in.readLine ();
for (int i = 0; i <s1.length (); i ++) {
int digit = Integer.valueOf (s1.substring (i, i + 1)). intValue ();
sb.append (faceVal [digit]);
}
String face = sb.reverse (). ToString ();
StringBuffer resultSb = new StringBuffer ();
for (int i = 0; i <face.length (); i ++) {
// weighted
if (i == 0) {
resultSb.append (level [0]);
}
else {
// Ten thousand processing
if ((i + 4)% 8 == 0) {
resultSb.append (level [4]);
}
// Billion processing
else if (i% 8 == 0) {
resultSb.append (level [5]);
}
else {
resultSb.append (level [i% 4]);
}
}
// Add face value
String temp = face.substring (i, i + 1);
resultSb.append (temp);
}

String result = resultSb.reverse (). ToString ();
The
The
result = result.replaceAll ("zero pick", "zero");
result = result.replaceAll ("Zero Bai", "Zero");
result = result.replaceAll ("零 仟", "零");
The
result = result.replaceAll ("[zero] +", "zero");
The
result = result.replaceAll ("zero circle", "circle");
result = result.replaceAll ("Zero Ten Thousand", "Ten Thousand");
result = result.replaceAll ("Zero Billion", "Billion");
The
System.out.println (result + "int");
} catch (Exception e) {
e.printStackTrace ();
}
}
}
Reply

Use magic Report

0

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-5-11 20:15:02
| Show all posts
public class Test {
/ **
* description is converted into Chinese capital form according to the number of RMB
*
* @param String
* type RMB figures
* @return String uppercase string
* @author date: 2002-10-20
* /
public String getChineseMoney (String moneyNum) {
// Array of Chinese characters
String [] chinese = new String [17];
String [] money = new String [2];
chinese [0] = "zero";
chinese [1] = "一";
chinese [2] = "Two";
chinese [3] = "Three";
chinese [4] = "Wan";
chinese [5] = "Wu";
chinese [6] = "Lu";
chinese [7] = "柒";
chinese [8] = "捌";
chinese [9] = "Jiu";
chinese [10] = "Pick up";
chinese [11] = "Bai";
chinese [12] = "仟";
chinese [13] = "10,000";
chinese [14] = "100 million";
chinese [15] = "元";
chinese [16] = "Entire";
money [0] = "corner";
money [1] = "cent";
// output uppercase string
String str_out = "";
// integer part string
String str_left = "";
// fractional string
String str_right = "";
// decimal point
String str_point = ".";
// Decimal position
int ponitLocation = moneyNum.indexOf (".");

// Number of decimal places
int pointLater = 0;
if (ponitLocation! = -1) {
pointLater = moneyNum.length ()-ponitLocation-1;
} else {
pointLater = moneyNum.length ();
}

// Separate the string into two parts
if (pointLater> 1) {
if (ponitLocation! = -1) {
str_left = moneyNum.substring (0, ponitLocation);
str_right = moneyNum.substring (ponitLocation + 1,
ponitLocation + 3);
} else {
str_left = moneyNum;
}

}
// Length of integer part string
int str_left_length;
str_left_length = str_left.length ();
// The length of the fractional string
int str_right_length;
str_right_length = str_right.length ();
// The zero character identification bit of the integer part
int flag = 0;
// The zero character identifier of the decimal part
int flag_zreo = 0;
// Start converting the integer part
for (int i = 0; i <= str_left.length ()-1; i ++) {

String str_l;
str_l = str_left.substring (i, i + 1);
int temp = Integer.parseInt (str_l);
switch (temp) {
case 1:
str_out = str_out + chinese [1];
break;
case 2:
str_out = str_out + chinese [2];
break;
case 3:
str_out = str_out + chinese [3];
break;
case 4:
str_out = str_out + chinese [4];
break;
case 5:
str_out = str_out + chinese [5];
break;
case 6:
str_out = str_out + chinese [6];
break;
case 7:
str_out = str_out + chinese [7];
break;
case 8:
str_out = str_out + chinese [8];
break;
case 9:
str_out = str_out + chinese [9];
break;
}
// Treatment of zeros in the integer part
if (temp == 0) {
flag ++;
if (str_left_length == 1) {
str_out = str_out + chinese [15];
}
if (str_left_length == 9) {
flag = 0;
str_out = str_out + chinese [14];
}
if (str_left_length == 5) {
flag = 0;
str_out = str_out + chinese [13];
}
// Determine whether to output zero, and decide according to its next digit: if it is zero, it will not output, otherwise it will output
if (str_left_length> = 2) {
String str_le = str_left.substring (i + 1, i + 2);
int tem = Integer.parseInt (str_le);
if ((flag == 1)&&(tem! = 0)) {
str_out = str_out + chinese [0];
} else {
flag = 0;
}
}
str_left_length--;
// System.out.println (str_left_length--);
} else {
flag = 0;
// The unit to add the integer part: pick, Bai, Qian, Wan, billion
switch (str_left_length) {

case 1:
str_out = str_out + chinese [15];
str_left_length--;
break;
case 2:
str_out = str_out + chinese [10];
str_left_length--;
break;
case 3:
str_out = str_out + chinese [11];
str_left_length--;
break;
case 4:
str_out = str_out + chinese [12];
str_left_length--;
break;
case 5:
str_out = str_out + chinese [13];
str_left_length--;
break;
case 6:
str_out = str_out + chinese [10];
str_left_length--;
break;
case 7:
str_out = str_out + chinese [11];
str_left_length--;
break;
case 8:
str_out = str_out + chinese [12];
str_left_length--;
break;
case 9:
str_out = str_out + chinese [14];
str_left_length--;
break;
case 10:
str_out = str_out + chinese [10];
str_left_length--;
break;
case 11:
str_out = str_out + chinese [11];
str_left_length--;
break;
case 12:
str_out = str_out + chinese [12];
str_left_length--;
break;
case 13:
str_out = str_out + chinese [13];
str_left_length--;
break;
}

}
}
// Handle the fractional part of the string
for (int i = 0; i <= str_right.length ()-1; i ++) {
String str_r;
str_r = str_right.substring (i, i + 1);
int temp1 = Integer.parseInt (str_r);
switch (temp1) {
case 1:
str_out = str_out + chinese [1];
break;
case 2:
str_out = str_out + chinese [2];
break;
case 3:
str_out = str_out + chinese [3];
break;
case 4:
str_out = str_out + chinese [4];
break;
case 5:
str_out = str_out + chinese [5];
break;
case 6:
str_out = str_out + chinese [6];
break;
case 7:
str_out = str_out + chinese [7];
break;
case 8:
str_out = str_out + chinese [8];
break;
case 9:
str_out = str_out + chinese [9];
break;

}
// Treatment of zeros in the fractional part
if (temp1 == 0) {
flag_zreo ++;
if (str_right_length == 2) {
// Determine whether to output zero, and decide according to its next bit: if it is zero, it will not output, otherwise
String str_ri = str_right.substring (i + 1, i + 2);
int temp = Integer.parseInt (str_ri);
if ((flag_zreo == 1)&&(temp! = 0)) {
str_out = str_out + chinese [0];
}
} else {
str_out = str_out + chinese [16];
}
str_right_length--;
} else {
// Add the angle and minutes of the decimal part
switch (str_right_length) {
case 1:
str_out = str_out + money [1];
str_right_length--;
break;
case 2:
str_out = str_out + money [0];
str_right_length--;
break;
}
}
}
return str_out;
}

public static void main (String [] a) {
Test test = new Test ();
System.out.println (test.getChineseMoney ("1050"));

}

}
Reply

Use magic Report

0

Threads

23

Posts

17.00

Credits

Newbie

Rank: 1

Credits
17.00

 China

Post time: 2020-5-18 19:15:01
| Show all posts
I am also invulnerable, I think.

import java.io. *;
public class a
{
   public static void main (String [] args)
   {
     String s = new String ();
     BufferedReader br = new BufferedReader (new InputStreamReader (System.in));

     while (true)
     {
        try {s = br.readLine ();} catch (Exception e) {}
       Convert c = new Convert (s.toCharArray ());
       System.out.println (c);
     }
   }
}
class Convert
{
  final String [] str1 = {"", "ten", "hundred", "thousand"};
  final String [] str2 = {"100 million", "10,000"};
  final String [] number = {"", "One", "Two", "Three", "Wu", "Wu", "Lu", "柒", "捌", "玖"};
  char [] num_char;
  StringBuffer sb = new StringBuffer ();
  int last;

  public Convert (char [] num)
  {
    num_char = num;
  }
  public String toString ()
  {
    last = num_char.length% 4;
    int pos = 0;
    add (sb, new String (num_char, 0, last));
    pos + = last;
    for (int i = (int) (num_char.length / 4); i> 0; i--)
    {
      if (i% 2 == 0) sb.append (str2 [0]);
      else sb.append (str2 [1]);
      add (sb, new String (num_char, pos, 4));
      pos + = 4;
    }
    if (last == 0) sb.deleteCharAt (0);
    return sb.toString ();
  }
  private void add (StringBuffer sb, String temp)
  {
    char [] temp2 = temp.toCharArray ();
    int length = temp.length ();
    for (int i = 0; i <length; i ++)
    {
      if (temp2 [i] == '0')
        if (sb.lastIndexOf ("zero")! = sb.length ()-1&&sb.length ()! = 0) sb.append ("zero"); else;
      else
      {
        sb.append (number [temp2 [i]-'0']);
        sb.append (str1 [length-i-1]);
      }
    }
    try {
      if (sb.lastIndexOf ("zero") == sb.length ()-1) sb.deleteCharAt (sb.lastIndexOf ("zero"));
    } catch (Exception e) {}
  }
}

The running result is:
1
one
10
One ten
100
One hundred
1000
One thousand
10000
Ten thousand
10000000
Ten million
102351225
One hundred and two hundred and thirty thirty one thousand one hundred and two hundred and ten
10250250210210
One hundred thousand two hundred thousand two hundred one hundred million one hundred thousand two hundred one thousand one hundred ten thousand two hundred one hundred ten
32135400213501232450123256903284230040
Three hundred and twenty-one thousand three hundred and five hundred million one hundred and thirty-nine thousand one hundred thirty-three thousand five hundred and one hundred million
Hundreds of thousands of people, ten thousand and ten thousand, three hundred and twenty million, two hundred and ten thousand, two hundred and thirty thousand, thirty thousand and ten
Reply

Use magic Report

1

Threads

21

Posts

19.00

Credits

Newbie

Rank: 1

Credits
19.00

 China

Post time: 2020-5-20 13:30:01
| Show all posts
You tough

Do n’t you worry about not writing enough time to write so much?


static String t1 = "Zero One Two Three, Wu Lu Qi Jiu Jiu";

static char [] n = {'仟', '', 'Pick up', '百'};

static char [] n1 = {'万', '亿'};

static char end = 'round';


public static void print (String value, int pos, boolean b) {
if (pos == 0) {
System.out.print (end);
return;
}
String value2 = value.substring (1, value.length ());
int printPos = value.charAt (0)-'0';
if (printPos! = 0) {
if (b == true)
System.out.print (t1.charAt (0));
System.out.print (t1.charAt (printPos));
System.out.print (printPos == 0? "": (N [pos% 4] == ''? "": N [pos% 4]));
}
if (pos% 4 == 1&&pos> 1) {
System.out.print (n1 [(pos / 4)-1]);
print (value2, pos-1, false);
return;
}
print (value2, pos-1, printPos == 0? true: false);
}

Instructions
print ("10010202070", 11, false);
Reply

Use magic Report

0

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-5-24 00:00:01
| Show all posts
I also encountered this problem when I went to the written test. At first I thought it was very simple, but later I found that there were many difficulties, mainly in the handling of 0. After returning home, it took a few minutes to write the correct procedure (only one hour during the written test!):


#include <stdio.h>
#include <iostream.h>
#include <string.h>
#include <stdlib.h>
#define MAX 0xffff
void main ()
{
char * temp1 [] = {"", "Ten", "Hundred", "Thousand"};
char * temp2 [] = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
enum {N, SHI, BAI, QIAN, WAN, YI};
char input [MAX];
char cache [MAX];
char cache1 [MAX];
bool zero = false;
int leng, i, prevMax;
cin >> input;
leng = strlen (input) -1;
for (i = 0; i <MAX&&i <= leng; i ++)
{
cache [i] = input [i];
if ((leng-i)% 4)
cache1 [i] = (leng-i)% 4;
else if (leng-i> 4&&! ((leng-i)% 8))
cache1 [i] = YI;
else if (leng-i! = 0)
cache1 [i] = WAN;
else
cache1 [i] = N;
}
cache [i] = cache1 [i] = 0;

for (i = 0; cache [i] == '0'; i ++);
while (1)
{
if (cache [i]! = '0')
{
prevMax = cache1 [i];
if (cache [i] == 0)
break;
if (zero == true)
cout << temp2 [0];
cout << temp2 [cache [i] -0x30];
if (cache1 [i] <4)
cout << temp1 [cache1 [i]];
else if (cache1 [i] == WAN)
cout << "10,000";
else if (cache1 [i] == YI)
cout << "100 million";
zero = false;
}
else
{
zero = true;
if (cache1 [i]> prevMax || cache1 [i] == YI)
{
prevMax = cache1 [i];
if (cache1 [i] <4)
cout << temp1 [cache1 [i]];
else if (cache1 [i] == 4)
cout << "10,000";
else
cout << "100 million";
}
}
i ++;
}
cout << endl;
}
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list