-PAT-java-5-23 币值转换 (20分)

输入一个整数(位数不超过9位)代表一个人民币值(单位为元),请转换成财务要求的大写中文格式。如23108元,转换后变成“贰万叁仟壹百零捌”元。为了简化输出,用小写英文字母a-j顺序代表大写数字0-9,用S、B、Q、W、Y分别代表拾、百、仟、万、亿。于是23108元应被转换输出为“cWdQbBai”元。

输入格式:

输入在一行中给出一个不超过9位的非负整数。

输出格式:

在一行中输出转换后的结果。注意“零”的用法必须符合中文习惯。

输入样例1:

813227345

输出样例1:

iYbQdBcScWhQdBeSf

输入样例2:

6900

输出样例2:

gQjB

挺麻烦的一道题

注意测试数据

0-a

1-b

200-cB

101001000-bYabBWbQ

100101000-bYabSWbQ

100011000-bYabWbQ

import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String[]dw = new String[10];

		dw[1] = "";
		dw[2] = "S";
		dw[3] = "B";
		dw[4] = "Q";
		dw[5] = "W";
		dw[6] = "S";
		dw[7] = "B";
		dw[8] = "Q";
		dw[9] = "Y";
		String[]num = new String[10];
		num[0] = "a";
		num[1] = "b";
		num[2] = "c";
		num[3] = "d";
		num[4] = "e";
		num[5] = "f";
		num[6] = "g";
		num[7] = "h";
		num[8] = "i";
		num[9] = "j";

		String s = sc.next();
		int len = s.length();
		if(len==1){		//输入一位数  单独考虑
			System.out.println(num[s.charAt(0)-48]);
		}
		else{
			for(int i=0 ;i<len ;i++){
				if(s.charAt(i)-48!=0){		//数位上不为0的情况
					System.out.print(num[s.charAt(i)-48]+dw[len-i]);
				}
				else if(i<len-1&&i!=len-5&&(s.charAt(i)-48==0&&s.charAt(i+1)-48!=0)){//数位上是0的情况   有多个连续的0 值输出一个
					System.out.print(num[s.charAt(i)-48]);
				}
				else if(len>5&&i==len-5&&s.charAt(i)-48==0){//万为是0的情况
					if(len==9&&s.charAt(1)-48==0&&s.charAt(2)-48==0&&s.charAt(3)-48==0){		//一亿的情况

					}else{
						System.out.print("W");
					}

				}
			}
		}
	}
}

时间: 2024-08-02 01:42:12

-PAT-java-5-23 币值转换 (20分)的相关文章

循环-19. 币值转换(20)

输入一个整数(位数不超过9位)代表一个人民币值(单位为元),请转换成财务要求的大写中文格式.如23108元,转换后变成"贰万叁仟壹百零捌"元.为了简化输出,用小写英文字母a-j顺序代表大写数字0-9,用S.B.Q.W.Y分别代表拾.百.仟.万.亿.于是23108元应被转换输出为"cWdQbBai"元. 输入格式: 输入在一行中给出一个不超过9位的非负整数. 输出格式: 在一行中输出转换后的结果.注意"零"的用法必须符合中文习惯. 输入样例1: 8

趣味PAT--循环-19. 币值转换(20)

One visible minute on the stage is attributed to ten years of invisible practice off the stage. "台上一分钟,台下十年功" 题目链接:循环-19. 币值转换(20) 输入一个整数(位数不超过9位)代表一个人民币值(单位为元),请转换成财务要求的大写中文格式.如23108元,转换后变成“贰万叁仟壹百零捌”元.为了简化输出,用小写英文字母a-j顺序代表大写数字0-9,用S.B.Q.W.Y分别代表

PAT乙级:1057 数零壹 (20分)

PAT乙级:1057 数零壹 (20分) 题干 给定一串长度不超过 105 的字符串,本题要求你将其中所有英文字母的序号(字母 a-z 对应序号 1-26,不分大小写)相加,得到整数 N,然后再分析一下 N 的二进制表示中有多少 0.多少 1.例如给定字符串 PAT (Basic),其字母序号之和为:16+1+20+2+1+19+9+3=71,而 71 的二进制是 1000111,即有 3 个 0.4 个 1. 输入格式: 输入在一行中给出长度不超过 105.以回车结束的字符串. 输出格式: 在

PAT 甲级 1027 Colors in Mars (20 分)(简单,进制转换)

1027 Colors in Mars (20 分) People in Mars represent the colors in their computers in a similar way as the Earth people. That is, a color is represented by a 6-digit number, where the first 2 digits are for Red, the middle 2 digits for Green, and the

pat 1136 A Delayed Palindrome(20 分)

1136 A Delayed Palindrome(20 分) Consider a positive integer N written in standard notation with k+1 digits a?i?? as a?k???a?1??a?0?? with 0≤a?i??<10 for all i and a?k??>0. Then N is palindromic if and only if a?i??=a?k?i?? for all i. Zero is written

pat 1054 The Dominant Color(20 分)

1054 The Dominant Color(20 分) Behind the scenes in the computer's memory, color is always talked about as a series of 24 bits of information for each pixel. In an image, the color with the largest proportional area is called the dominant color. A str

PAT Basic 1069 微博转发抽奖 (20 分)

小明 PAT 考了满分,高兴之余决定发起微博转发抽奖活动,从转发的网友中按顺序每隔 N 个人就发出一个红包.请你编写程序帮助他确定中奖名单. 输入格式: 输入第一行给出三个正整数 M(≤ 1000).N 和 S,分别是转发的总量.小明决定的中奖间隔.以及第一位中奖者的序号(编号从 1 开始).随后 M 行,顺序给出转发微博的网友的昵称(不超过 20 个字符.不包含空格回车的非空字符串). 注意:可能有人转发多次,但不能中奖多次.所以如果处于当前中奖位置的网友已经中过奖,则跳过他顺次取下一位. 输

PAT - JAVA-5-18 二分法求多项式单根 (20分)

二分法求函数根的原理为:如果连续函数f(x)f(x)在区间[a, b][a,b]的两个端点取值异号,即f(a)f(b)<0f(a)f(b)<0,则它在这个区间内至少存在1个根rr,即f(r)=0f(r)=0. 二分法的步骤为: 检查区间长度,如果小于给定阈值,则停止,输出区间中点(a+b)/2(a+b)/2:否则 如果f(a)f(b)<0f(a)f(b)<0,则计算中点的值f((a+b)/2)f((a+b)/2): 如果f((a+b)/2)f((a+b)/2)正好为0,则(a+b)

【PAT】B1044 火星数字(20 分)

/* 火星文有两位,第二位为0不输出 */ #include<stdio.h> #include<algorithm> #include<string.h> #include<ctype.h> using namespace std; char arr[20]={0}; char data[13][2][5]={ {"tret","tret"}, {"jan","tam"}, {