1082 Read Number in Chinese (25 分)

在这里插入图片描述
1082 Read Number in Chinese (25 分)
Given an integer with no more than 9 digits, you are supposed to read it in the traditional Chinese way. Output Fu first if it is negative. For example, -123456789 is read as Fu yi Yi er Qian san Bai si Shi wu Wan liu Qian qi Bai ba Shi jiu. Note: zero (ling) must be handled correctly according to the Chinese tradition. For example, 100800 is yi Shi Wan ling ba Bai.

Input Specification:
Each input file contains one test case, which gives an integer with no more than 9 digits.

Output Specification:
For each test case, print in a line the Chinese way of reading the number. The characters are separated by a space and there must be no extra space at the end of the line.

Sample Input 1:
-123456789
Sample Output 1:
Fu yi Yi er Qian san Bai si Shi wu Wan liu Qian qi Bai ba Shi jiu
Sample Input 2:
100800
Sample Output 2:
yi Shi Wan ling ba Bai

#include<iostream>
using namespace std;
string digits[10] = { "ling","yi","er","san","si","wu","liu","qi","ba","jiu" };
string units[5] = { "Yi","Wan","Qian","Bai","Shi" };
int main() {
	string s;
	cin >> s;
	if (s[0] == '-') {
		cout << "Fu ";
		s = s.substr(1, s.length() - 1);
	}
	if (s.length() == 9) {
		cout << digits[s[0] - '0'] << " " << units[0] << " ";
		s = s.substr(1, s.length() - 1);
	}
	if (s.length() <= 8&&s.length()>=5) {
		string t= s.substr(0, s.length() - 4);
		s = s.substr(s.length() - 4, 4);
		if (t == "0000") goto next;
		bool flag = false;
		for (int i = 0; i < t.length() ; i++) {
			if (t[i] == '0'&&flag==false) cout << digits[0] << " ";
			else {
				if (t[i] == '0' && flag == true) break;
 				if(t[i]!='0') cout << digits[t[i] - '0'] << " ";
				if (t.length() == 4) {
					if (i == 0 && t[1] == '0' && t[2] == '0' && t[3] == '0') {
						cout << units[2] << " ";
						flag = true;
					}
					else if(i==0)cout << units[2] << " ";
					if (i == 1 && t[2] == '0' && t[3] == '0') { 
						cout << units[3] << " "; flag = true;
					}
					else if(i==1)cout << units[3] << " ";
					if (i == 2 && t[3] == '0') { 
						cout << units[4] << " ";
						flag = true;
					}
					else if(i == 2) cout << units[4] << " ";
				}
				else if (t.length() == 3) {
					if (i == 0 && t[1] == '0' && t[2] == '0') {
						cout << units[3] << " ";
						flag = true;
					}
					else if (i == 0)cout << units[3] << " ";
					if (i == 1 && t[2] == '0') {
						cout << units[4] << " ";
						flag = true;
					}
					else if (i == 1)cout << units[4] << " ";
				}
				else if (t.length() == 2) {
					if (i == 0 && t[1] == '0') {
						cout << units[4] << " ";
						flag = true;
					}
					else if (i == 0)cout << units[4] << " ";
				}
			}
		}
		cout << units[1]<<" ";
	}
	next:
	if (s.length() <= 4 && s.length() >= 1) {
		string t = s;
		bool flag = false;
		if (t == "0") { cout << digits[0]; goto last; }
		if (t == "0000") goto last;
		if (t[0] == '0' && t[1] == '0' && t[2] == '0') {
			cout << digits[0] << " " << digits[t[3] - '0']; goto last;
		}
		for (int i = 0; i < t.length() ; i++) {
			if (t[i] == '0' && flag == false) cout << digits[0] << " ";
			else {
				if (t[i] == '0' && flag == true) break; 
				if (t[i] != '0' && i != t.length() - 1) cout << digits[t[i] - '0'] << " ";
				else cout << digits[t[i] - '0'];
				if (t.length() == 4) {
					if (i == 0 && t[1] == '0' && t[2] == '0' && t[3] == '0') {
						cout << units[2];
						flag = true;
					}
					else if (i == 0)cout << units[2] << " ";
					if (i == 1 && t[2] == '0' && t[3] == '0') {
						cout << units[3]; flag = true;
					}
					else if (i == 1)cout << units[3] << " ";
					if (i == 2 && t[3] == '0') {
						cout << units[4];
						flag = true;
					}
					else if (i == 2) cout << units[4] << " ";
				}
				else if (t.length() == 3) {
					if (i == 0 && t[1] == '0' && t[2] == '0') {
						cout << units[3];
						flag = true;
					}
					else if (i == 0)cout << units[3] << " ";
					if (i == 1 && t[2] == '0') {
						cout << units[4];
						flag = true;
					}
					else if (i == 1)cout << units[4] << " ";
				}
				else if (t.length() == 2) {
					if (i == 0 && t[1] == '0') {
						cout << units[4];
						flag = true;
					}
					else if (i == 0)cout << units[4] << " ";
				}
			}
		}
	}
	last:
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: "cannot read jlink version number" 的意思是无法读取JLink的版本号。 JLink是一种用于连接和调试嵌入式设备的工具。当出现 "cannot read jlink version number" 错误时,可能是由于以下原因之一: 1. JLink工具未正确安装或配置。 2. JLink工具与目标设备之间的连接出现了问题。 3. 目标设备未正确配置或连接。 要解决这个问题,你可以尝试重新安装和配置JLink工具,并确保正确连接到目标设备。另外,你还可以检查目标设备是否正确配置,例如是否开启了调试模式等。如果问题仍然存在,可能需要进一步检查和排除故障。 ### 回答2: 在使用JLink调试器设备时,如果出现“cannot read jlink version number”的错误提示,可能出现以下几种情况: 一是连接问题。在使用JLink设备时,需要将设备正确连接到计算机上。因此,如果出现“cannot read jlink version number”的错误提示,首先需要检查设备是否连接到计算机。可以拔插一下设备,重新连接,看看是否可以解决问题。 二是软件配置问题。JLink设备需要安装相应的驱动程序和软件才能正常运行。因此,如果出现“cannot read jlink version number”的错误提示,需要检查软件是否配置正确。可以重新安装JLink驱动程序和相应的调试软件,看看是否可以解决问题。 三是硬件故障问题。如果以上两种情况都排除了,那么可能是JLink设备本身出现了硬件故障。这时候需要联系设备厂商或者售后服务,进行检修或更换设备。 无论出现什么问题,我们要快速排查问题,找到原因并解决。只有这样,才能保证设备正常工作,提高工作效率,达到预期的调试效果。 ### 回答3: JLink是较为常用的一款微控制器仿真器,该错误是指在与JLink进行交互的过程中,无法读取到JLink的版本号。这可能涉及到以下几个方面的问题: 1. 驱动问题:如果JLink驱动没有成功安装或已损坏,则无法与计算机进行正常通信。因此,在使用JLink时应该先检查驱动的状态,看是否需要重新安装或更新。 2. 连接问题:连接JLink读卡器时,可能存在物理连接松动、插口损坏或拔出了连接线的情况,这会导致无法正确读取版本号。解决办法是检查并重新连接所有的接口。 3. JLink硬件问题:如果JLink本身存在硬件问题,那么软件就无法正常读取其嵌入式版本号。这种情况下,只能通过更换JLink硬件解决问题。 4. 冲突问题:除了驱动外,其他占用端口的应用程序也可能对JLink的读取造成干扰。可以尝试关闭所有其他程序,只保留JLink调试器程序运行,然后重启计算机,再次尝试读取JLink版本号。 总之,无法读取JLink版本号的问题可能是多种多样的,需要逐一排查并采取相应的解决办法。如果以上方法都不奏效,则建议联系JLink官方技术支持或售后服务,寻求更详细的帮助。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值