A1082. Read Number in Chinese (25)

《数据结构》知识点汇总+算法代码总结【全】 写在前面:本文写于吴签时期,在家备考时刷完数据结构王道书之后想着把书中重点梳理汇总一下。本文内容包括但不局限于王道数据结构每章的知识点及其课后习题所涵盖的知识点。本人曾在大三期间打过一些程序设计类比赛,所以本文所涉及到的代码不一定局限于王道书,但思想都一样。 期末复习和备考408均可使用第一章:绪论(不在考研大纲但很重要)第二章:线性表第三章:栈和队列第四章:串第五章:树与二叉树第六章:图第七章:查找 第一章:绪论(不在考研大纲但很重要) 数据结构三要素:逻辑结构、存储结构、数据的运算;其中逻辑结构包括线 阅读详情

A1082

题目描述如下:

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

我的AC代码是:

#include <cstdio>
#include <cstring>
char trans[10][5] = { "ling","yi","er","san","si","wu","liu","qi","ba","jiu" };
char other[4][5] = { "","Shi","Bai","Qian"};
char num[10];
int main() {
    int n;
    scanf("%d", &n);
    bool block = false;//表示需要一个空格
    if (n < 0) {
        printf("Fu");
        n = -n;
        block = true;
    }
    else if (n == 0) {
        printf("ling"); return 0;
    }
    sprintf(num, "%d", n);
    int m = strlen(num);
    int section = (m - 1) / 4 + 1, contain, info = 0;
    bool flag, fullzero;
    while (section) {
        flag = false;
        fullzero = true;
        contain = m % 4;
        if (contain == 0)contain = 4;
        for (int i = 0; i < contain; i++) {
            if (num[info + i] == '0') {
                flag = true;
            }
            else {
                if (flag)
                    printf(" ling");
                flag = false;
                fullzero = false;
                if (block)
                    printf(" %s", trans[num[info + i] - '0']);
                else
                    printf("%s", trans[num[info + i] - '0']);
                int k = contain - i - 1;
                if (k)printf(" %s", other[k]);
                block = true;
            }
        }
        m -= contain;
        if (!fullzero) {
            switch (section) {
            case 3:printf(" Yi"); block = true; break;
            case 2:printf(" Wan"); block = true; break;
            }
        }
        section--;
        info += contain;
    }
    return 0;
}

注意几个例子:

800000000 ba Yi

800000008 ba Yi ling ba

808080808 ba Yi ling ba Bai ling ba Wan ling ba Bai ling ba

880808080 ba Yi ba Qian ling ba Shi Wan ba Qian ling ba Shi

80008000 ba Qian Wan ba Qian

0 ling

8 ba


【100分】【等和子数组最小和】 逆序排序,这样能够使得在分组时优先选取较大的元素,以便将元素分配到较小的子集中,从而使得每个子集的和相对均衡。给定一个数组nums,将元素分为若干个组,使得每组和相等,求出满足条件的所有分组中,组内元素和的最小值。分成若干个组,使得每组的和相等,并求出满足条件的所有分组中,组内元素和的最小值。在递归的过程中,我们需要注意一个优化点,即避免将相同和的桶重复计算。4 个子集(5),(1,4),(2,3),(2,3)2 个子集(5, 1, 4),(2,3, 2,3)个子集,则返回子集和的最小值,如果不能,则将。 阅读详情

相关推荐

神经网络学习笔记-波尔兹曼(Boltzmann)机

Boltzmann机是一种反馈随机神经网络 两种输出状态,单极性0或1。输出状态的取值根据概率统计法则决定,这种概率统计法则类似Boltzmann分布,部分反馈 它在神经元状态变化中引入了统计概率,网络的平衡状态服从Boltzmann分布,网络运行机制基于模拟退火算法。 离散Hopfield神经网络+模拟退火+隐单元=Boltzman机 DHNN全反馈,转移函数:符号函数 BM机网络拓扑...

求易学堂的博客 2615

A1082 Read Number in Chinese (25 分)

虽然在网上看到很多大佬评价这题不难,但是个人感觉这道题目还是很难的 以下是在算法笔记中看到的解法。虽然这个解法在pta里面通过了,但是到牛客网上却通过不了: 测试用例: 100001234 对应输出应该为: yi Yi ling yi Qian er Bai san Shi si 你的输出为: yi Yi yi Qian er Bai san Shi si 确实存在一定问题,但是经过修改,反而又出...

A_Aria的博客 299

亚马逊广告接口 amazon advertising

亚马逊广告接口官方说明:https://advertising.amazon.com/API/docs/en-us/setting-up/account-setup 一:注册aws开发者账号 注册地址:https://developer.amazon.com 二:填写注册资料 三:进入控制台,生成安全配置文件 进入 Login with Amazon 菜单: 创建配置文件: 四:申请广告接入权限 申请地址:https://advertising.amazon.com/zh-cn/about-api

lzy66666的博客 4776

PAT A1082 2019.07.16 【string】

1082Read Number in Chinese(25分) Given an integer with no more than 9 digits, you are supposed to read it in the traditional Chinese way. OutputFufirst if it is negative. For example, -123456789 ...

一个非计算机专业的 博客 260

正交试验-方差分析-数据展现形式

方差分析(ANOVA, Analysis of Variance)用于比较多个组之间的均值差异,确定因素对响应变量的显著性影响。示例分析。

m0_58326994的博客 1971

多模态论文笔记——BLIP

本文详细介绍这几年AIGC火爆的隐藏功臣,多模态模型:BLIP。

haopinglianlian的博客 2454

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 Qi

s136424的博客 444

把注释掉的代码删除掉:在 SAP ABAP 团队里打造可回溯、可测试、可演进的代码库

摘要 SAP ABAP项目中常见的"注释掉代码"反模式存在严重隐患:它增加代码噪音,制造虚假安全感,并可能引发安全和合规风险。Clean ABAP指南明确建议删除这类代码,理由包括: 版本控制系统已提供完整历史回溯能力 注释代码会误导开发者,增加理解成本 临时禁用需求应通过Feature Toggle实现 必须保留的参考代码应放入$TMP等隔离区域 团队应建立自动化检查机制,将"删除注释代码"纳入工程规范,确保代码库只表达当前有效的行为逻辑。在AI时代,可以利用工具辅

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 2451

Pat甲级题目刷题分享+算法笔记提炼 ---------------第一部分 基本数据操作与常用算法

一、算法笔记提炼     ·  数学相关      1. 最大公约数+最小公倍数(只需要记住 定理即可)       gcd(a,b) = gcd(b,a%b);   意思是:a与b的最大公约数 即 b与a%b的最大公约数 而 0 与数a的最大公约数为数a,自然递归边界很容易得知 int gcd(int a,int b) { if (b==0) { return a; } re...

huangwei2014的博客 1009

【Bluetooth蓝牙开发】一、开篇词 | 打造全网最详细的Bluetooth开发教程

1、开篇词 2、蓝牙开发入门 3、蓝牙协议栈总览 4、蓝牙协议栈——物理层 5、蓝牙协议栈——链路层 6、蓝牙协议栈——传输层 7、蓝牙协议栈——L2CAP协议 8、蓝牙协议栈——ATT协议 9、蓝牙协议栈——GATT协议 10、蓝牙通信流程分析 11、蓝牙协议栈——Bluez交叉编译 12、蓝牙调试工具汇总

Donge's Blog 1万+

点云处理实操(四) -PCL中的点云三角化

点云处理实操(四) -PCL中的点云三角化

cangqiongxiaoye的博客 939

PAT甲级刷题之路——A1082 Read Number in Chinese

PAT A1082 Read Number in Chinese(25分)原题如下题目大意自己的想法答案反馈错误1错误2AC代码结语 原题如下 题目大意 给出一个不超过9个数字的整数,需要用中文读法输出,如果前面有负号,需要先输出"Fu"。注意:零需要根据中国方式来放置。 自己的想法 先通过string储存 两个非零数之间无论多少零只读一个零 尾部的零不读 第九位后加‘Yi’,第五位后加’W...

qq_43677396的博客 635

青岛鼎信Java开发面试题及参考答案(3万字长文,多张原理图)

MySQL 的事务特性有哪些? MySQL 事务具有四个重要特性,被称为 ACID 特性。 原子性(Atomicity):事务是一个不可分割的工作单位,事务中的操作要么全部执行,要么全部不执行。例如,在银行转账场景中,从账户 A 转账到账户 B,包括扣减账户 A 的金额和增加账户 B 的金额这两个操作必须作为一个整体来完成。如果在执行过程中发生错误,比如系统崩溃或者数据库出现故障,那么已经执行的部分必须全部回滚,就好像整个转账操作从未发生过一样。 一致性(Consistency):事务必须

大模型大数据攻城狮的专栏 1089

A1082 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 ex...

weixin_30722589的博客 173

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

PAT甲级A1082 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 ...

vir_lee的博客 425

android 蓝牙通讯demo

android 下蓝牙通讯demo,实现了发现蓝牙,使能蓝牙,通过蓝牙发送消息。

PAT A1082 Read Number in Chinese (25分)

题意:按照中文习惯读出9位的数字,首先一条规则,从低位开始按照每4位为一节,依次为个节,万节,亿节。明白了这条规则这题就算做了40%。先转置字符串,用到left和right两个游标,首先第一个while将两个游标定位到最高节,然后第二个while每次让right--,直到left==right,说明到了节尾了,该输出节单位了。输出之后,让right--到下一节头,left跳到下一节尾,开始下一...

tangobravo的博客 189

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

PAT A1082 Read Number in Chinese (25 分)

PAT A1082 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 li

weixin_48165493的博客 170

A1082 Read Number in Chinese (25分)【C语言】

A1082 Read Number in Chinese (25分)【C语言】 原题链接 题目描述: 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 Sh

SASAKI_130的博客 227

PAT-A 1082 Read Number in Chinese (25 分)

思路: 1.当我们在读123456789时,将1作为一组,读1“亿”,将2345作为一组,读两千三百四十五“万”,将6789作为一组,读六千七百八十九。显然,我们读数字(不超过10000亿)的时候是从低位到高位,每4位作为一组,读出这些数,再加上单位,如“万”和“亿”。 2.如果我们有一个函数,可以使用拼音读出(0,9999]的数字,那么只需要将数字从低到高,以4位为单位读出,然后再加上相应的权重,如“万”。 3.每四位为一节,节与节之间可能需要读0,或者某一节全为0,这些情况需要特殊处理。

qq_38127801的博客 255

PAT A1082 Read Number in Chinese (25 分) 字符串

题目大意:给出一个不超过九位的数,按照中文读法输出,并且注意"0"的读法,比如,10100,要读成 "yi Wan ling yi Bai"。 非常繁琐的一道题,主要的问题在于”0“的读法,处理这一问题的策略是,按照从高位到低位,顺序读入每个数。设置一个变量表明是否应当输出"ling"。如果当前读到了非零数字,而且与前一个非零数字中间有0的话,除了一种情况外,都应该输出”ling...

HackingGate的博客 253

PAT A 1082 Read Number in Chinese (25 分)

思路 **使用整型num读入,若num<0输出"Fu "并转换为正数,若num为0,输出"ling"。 将num转换为字符串,并i = 0开始遍历,j = 串长 - 1开始递减,记录该位是第几位**

Siumai's Blog 193

【PAT】A1082. Read Number in Chinese (25)

A1082. Read Number in Chinese (25)易错点在于对于 ling的输出和空格的处理

lilydedbb的博客 504

【PAT】A1082 Read Number in Chinese (25point(s))

文章目录A1082 Read Number in Chinese (25point(s))Input Specification:Output Specification:Sample Input 1:Sample Output 1:Sample Input 2:Sample Output 2:CodeAnalysis Author: CHEN, Yue Organization: 浙江大学 Ti...

Duke 253

A1082 Read Number in Chinese (25) 字符串处理

本题是字符串转换问题,在设计计算的时候很明显是以四个数字为一节进行计算,所以可以每次分成四个数字一组进行判断,用left和right来表示边界,设计千百十计算,最后利用len和right来设计万和亿的计算就好了。 #include<cstdio> #include<cstring> char num[10][5]={"ling","yi","er","san","si","wu","liu","qi","ba","jiu"}; char wei[5][5]={"Shi","Bai",

coder_Kim的博客 163
下一篇: A1001. A+B Format (20)
DemonInside
博客等级 码龄10年 1粉丝 18原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值