1082 Read Number in Chinese

本文详细解析了如何将中文数字转换为传统中文读法,特别关注于0的正确处理方式,包括前置0、中间0及末尾0的不同读法。通过具体示例和代码实现,展示了如何将任意不超过9位的整数按中国习俗读出。

1082 Read Number in Chinese (25 point(s))

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

这是一道比较复杂的模拟题。

中文中读数是按照4位一读,read()函数实现。关键是0的处理,包括4位中前置0的处理(read()中实现)、4位中间的0的处理(主程序中实现)、末尾0的处理(不需要处理)。

 

#include<iostream>
using namespace std;
string words[110];
string digit[10]={"ling","yi","er","san","si","wu","liu","qi","ba","jiu"};
int idx = 0;
void read(int n){
	int thousand,hundred,tens,ones;
	thousand = n/1000;
	n = n - thousand*1000;
	hundred = n/100;
	n = n - hundred*100;
	tens = n / 10;
	ones = n % 10;
	bool flag=false;
	if(thousand!=0){
		words[idx++]=digit[thousand];
		words[idx++]="Qian";
		if(hundred==0&&(tens>0||ones>0)){
			words[idx++]=digit[0]; 
		}
	}
	if(hundred!=0){
		words[idx++]=digit[hundred];
		words[idx++]="Bai";
		if(tens==0&&ones>0) words[idx++]=digit[0];
	}
	if(tens!=0){
		flag=false;
		words[idx++]=digit[tens];
		words[idx++]="Shi";
	}
	if(ones!=0) words[idx++]=digit[ones];
}
int main(void){
	int n;cin>>n;
	if(n<0) {
		words[idx++]="Fu";
		n=-n;
	}
	if(n==0) words[idx++]=digit[0];
	int hm=0,tt=0;
	if(n>=100000000){
		hm = n/100000000;
		words[idx++]=digit[hm];
		words[idx++]="Yi";
		n = n-hm*100000000;
	}
	if(n>=10000){
		tt = n/10000;
		if(hm>0&&tt<1000&&tt>0) words[idx++]=digit[0];//前置0 
		read(tt);
		words[idx++]="Wan";
		n = n-tt*10000;
	}
	if(n>0){
		if((tt>0||hm>0)&&n<1000&&n>0) words[idx++]=digit[0];
		read(n);
	}
	for(int i=0;i<idx;i++){
		if(i==0) cout<<words[i];
		else cout<<" "<<words[i];
	}
	cout<<endl;
	return 0;
}

 

3) 使用HiveQL查询每科平均分,显示字段:科目、平均分。数据已经上传至数据库。hive (hive)> set hive.exec.mode.local.auto=true; hive (hive)> SELECT 'Math' AS subject, ROUND(AVG(Math), 2) AS avg_score FROM score > UNION ALL > SELECT 'Computer' AS subject, ROUND(AVG(Computer), 2) AS avg_score FROM score > UNION ALL > SELECT 'Chinese' AS subject, ROUND(AVG(Chinese), 2) AS avg_score FROM score; Query ID = hadoop_20251224185834_8ee4a2cc-62e1-4a3c-b74e-16e24b8a22ca Total jobs = 4 Launching Job 1 out of 4 Number of reduce tasks determined at compile time: 1 In order to change the average load for a reducer (in bytes): set hive.exec.reducers.bytes.per.reducer=<number> In order to limit the maximum number of reducers: set hive.exec.reducers.max=<number> In order to set a constant number of reducers: set mapreduce.job.reduces=<number> Job running in-process (local Hadoop) 2025-12-24 19:00:06,598 Stage-1 map = 100%, reduce = 100% Ended Job = job_local164584697_0001 Launching Job 2 out of 4 Number of reduce tasks determined at compile time: 1 In order to change the average load for a reducer (in bytes): set hive.exec.reducers.bytes.per.reducer=<number> In order to limit the maximum number of reducers: set hive.exec.reducers.max=<number> In order to set a constant number of reducers: set mapreduce.job.reduces=<number> Job running in-process (local Hadoop) 2025-12-24 19:00:37,785 Stage-3 map = 0%, reduce = 0% Ended Job = job_local459353491_0002 with errors Error during job, obtaining debugging information... FAILED: Execution Error, return code 2 from org.apache.hadoop.hive.ql.exec.mr.MapRedTask MapReduce Jobs Launched: Stage-Stage-1: HDFS Read: 1568 HDFS Write: 784 SUCCESS Stage-Stage-3: HDFS Read: 0 HDFS Write: 0 FAIL Total MapReduce CPU Time Spent: 0 msec hive (hive)> 但报错了
12-25
【CNN-GRU-Attention】基于卷积神经网络和门控循环单元网络结合注意力机制的多变量回归预测研究(Matlab代码实现)内容概要:本文介绍了基于卷积神经网络(CNN)、门控循环单元网络(GRU)与注意力机制(Attention)相结合的多变量回归预测模型研究,重点利用Matlab实现该深度学习模型的构建与仿真。该模型通过CNN提取输入数据的局部特征,利用GRU捕捉时间序列的长期依赖关系,并引入注意力机制增强关键时间步的权重,从而提升多变量时间序列回归预测的精度与鲁棒性。文中涵盖了模型架构设计、训练流程、参数调优及实际案例验证,适用于复杂非线性系统的预测任务。; 适合人群:具备一定机器学习与深度学习基础,熟悉Matlab编程环境,从事科研或工程应用的研究生、科研人员及算法工程师,尤其适合关注时间序列预测、能源预测、智能优化等方向的技术人员。; 使用场景及目标:①应用于风电功率预测、负荷预测、交通流量预测等多变量时间序列回归任务;②帮助读者掌握CNN-GRU-Attention混合模型的设计思路与Matlab实现方法;③为学术研究、毕业论文或项目开发提供可复现的代码参考和技术支持。; 阅读建议:建议读者结合Matlab代码逐模块理解模型实现细节,重点关注数据预处理、网络结构搭建与注意力机制的嵌入方式,并通过调整超参数和更换数据集进行实验验证,以深化对模型性能影响因素的理解。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值