HJ101 输入整型数组和排序标识,对其元素

华为OD机试“HJ101 输入整型数组和排序标识,对其元素按照升序或降序进行排序”Java编程解答 输入整型数组和排序标识,对其元素按照升序或降序进行排序数据范围: 1≤n≤1000,元素大小满足 0≤val≤100000输入描述:第一行输入数组元素个数第二行输入待排序的数组,每个数用空格隔开第三行输入一个整数0或1。0代表升序排序,1代表降序排序 阅读详情

描述

输入整型数组和排序标识,对其元素按照升序或降序进行排序

数据范围: 1≤n≤1000 1≤n≤1000  ,元素大小满足 0≤val≤100000 0≤val≤100000 

输入描述:

第一行输入数组元素个数
第二行输入待排序的数组,每个数用空格隔开
第三行输入一个整数0或1。0代表升序排序,1代表降序排序

输出描述:

输出排好序的数字

输入:8
1 2 4 9 3 64 55 25
输出:
1 2 3 4 9 25 55 64
#include <iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main() {
    int n = 0;
    int val = 0;
    int sequence = 0; //1
    vector<int> vec;
    while (cin >> n) {
    for(int l=0;l<n;l++){
        cin >>val;
         vec.push_back(val);
    }
    cin >> sequence;
    sort(vec.begin(),vec.end());//up
    if(sequence==1) {
    //down
    int len=vec.size();
        for(int i=len-1;i>=0;i--){
            cout<<vec[i]<<" ";
        }
        cout<<endl;
    }
    else if(sequence==0){
        vector<int>::iterator it;
        for(it= vec.begin();it!=vec.end();it++)cout<<*it<<" ";
        cout<<endl;

    }

}
return 0;
}
// 64 位输出请用 printf("%lld")

 

【华为机试题 HJ101】输入整型数组和排序标识,对其元素按照升序或降序进行排序 输入整型数组和排序标识,对其元素按照升序或降序进行排序 阅读详情

相关推荐

【牛客网华为机试】HJ101 输入整型数组和排序标识,对其元素按照升序或降序进行排序

题目 描述 输入整型数组和排序标识,对其元素按照升序或降序进行排序 输入描述: 第一行输入数组元素个数 第二行输入待排序的数组,每个数用空格隔开 第三行输入一个整数0或1。0代表升序排序,1代表降序排序 输出描述: 输出排好序的数字 示例1 输入: 8 1 2 4 9 3 55 64 25 0 输出: 1 2 3 4 9 25 55 64 示例2 输入: 5 1 2 3 4 5 1 输出: 5 4 3 2 1 解题思路 (1)获取输入的整数列表 (2)用so.

202xxx的博客 464

华为机考攻略(python)--字符串操作【9题】(第五题HJ101输入整型数组和排序标识)

从思维的原点出发,思想者就成为思维之旅的苦行者和拓荒者。

用余生去守护的博客 652

Android逆向实战:抖音聊天记录数据库解析与导出(附完整SQL查询)

本文提供了一份Android逆向实战指南,详细解析了抖音聊天记录数据库的结构与导出方法。通过定位核心的`im.db`数据库文件,深度解读conversation_list、msg等关键表结构,并附上完整的SQL查询语句,帮助开发者或研究人员安全、合规地提取和分析本地聊天数据,适用于移动安全研究与数据分析场景。

mango的博客 867

【HJ101】输入整型数组和排序标识,对其元素按照升序或降序进行排序

【牛客刷题】华为机试:输入整型数组和排序标识,对其元素按照升序或降序进行排序

Caso_卡索的博客 1591

Python邮件自动化实战:基于imaplib和email库的高效邮件管理方案

本文详细介绍了如何使用Python的imaplib和email库实现高效邮件自动化管理。通过实战案例展示自动收取、解析邮件、下载附件等核心功能,帮助开发者快速构建企业级邮件处理系统,大幅提升工作效率。特别适合需要处理大量邮件的金融、数据分析等场景。

weixin_30500105的博客 621

RAG优化实战:微调Embedding模型提升检索精度全流程

在构建基于大语言模型(LLM)的问答系统时,检索增强生成(RAG)架构是关键技术路线。其核心原理在于,通过Embedding模型将文本转换为高维向量,并在向量空间中进行语义相似度计算,从而实现精准检索。这项技术的核心价值在于,它能有效利用专属知识库,为大模型提供准确的上下文信息,从而减少“幻觉”并提升答案的专业性与时效性。然而,通用Embedding模型在面对医疗、法律、金融等垂直领域的专业术语和行话时,往往存在语义理解偏差,导致检索不准,成为RAG系统的关键瓶颈。为解决此问题,微调(Fine-tuning

weixin_34088583的博客 503

华为机试题:HJ101 输入整型数组和排序标识,对其元素按照升序或降序进行排序(python)

输入整型数组和排序标识,对其元素按照升序或降序进行排序(python)

📷 图像处理践行者 | 传统算法 · 深度学习 · 多模态 | 分享实战经验与技术洞见,探索从像素到智能的无限可能。 1235

FOC实战笔记:RC吸收电路的设计考量与参数调优

本文深入探讨了FOC驱动器中RC吸收电路的设计与调优。针对MOS管开关过程中的电压尖峰问题,详细阐述了RC电路的钳位与能量吸收原理,并提供了从参数计算、实验调试到布局布线的完整实战指南,旨在帮助工程师有效提升系统可靠性与稳定性。

weixin_29219539的博客 277

华为机试-101-入门-HJ101.输入整型数组和排序标识,对其元素按照升序或降序进行排序

【代码】华为机试-101-入门-HJ101.输入整型数组和排序标识,对其元素按照升序或降序进行排序

tttzzzqqq2018的博客 528

【ComfyUI】FluxKontext 身形调优与体态增强

AI身形调优与体态增强解决方案 该工作流通过Flux系列模型实现人物体态的智能化增强,主要特点包括: 采用UNet主体模型+双文本编码器+身形增强LoRA的架构组合 通过ReferenceLatent保持原始姿态的同时强化胸腰臀比例 完整工作流包含图像加载、文本编码、潜空间映射等8个核心节点 支持自动化的前后效果对比展示 应用优势: 保持人物自然姿态的前提下实现局部强化 支持通过Prompt精确控制增强方向 适用于摄影后期、角色美化等创作场景 输出效果稳定且风格统一 使用方

Mr数据杨 1304

fatal: unable to access ‘https://github.com/‘: Recv failure: Connection was reset 解决方案

本文主要介绍了fatal: unable to access ‘https://github.com/’: Recv failure: Connection was reset 解决方案,希望能对使用github的同学们有所帮助。 文章目录 1. 问题描述 2. 解决方案

weixin_43178406的博客 2万+

HJ101 输入整型数组和排序标识,对其元素按照升

描述 输入整型数组和排序标识,对其元素按照升序或降序进行排序 数据范围:,元素大小满足 输入描述: 第一行输入数组元素个数 第二行输入待排序的数组,每个数用空格隔开 第三行输入一个整数0或1。0代表升序排序,1代表降序排序 输出描述: 输出排好序的数字 #include<stdio.h> int main(int argc,char const*argv[])//argc是命令行总的参数个数,argv[]为保存命令行参数的字符串指针, { int num=0,sf...

weixin_45667141的博客 270

Spring Boot入门(13):Mybatis-Plus之条件构造器使用手册:精通让你快速提高查询效率的技巧!

化繁为简,MP 中条件构造器的使用,极其详细.

**My Coding Family** 3万+

HJ101 输入整型数组和排序标识,对其元素按照升序或降序进行排序

输入一个只包含小写英文字母和数字的字符串,按照不同字符统计个数由多到少输出统计结果,如果统计的个数相同,则按照ASCII码由小到大排序输出。一个字符串,为不同字母出现次数的降序表示。若出现次数相同,则按ASCII码的升序输出。数据范围:字符串长度满足 1≤𝑙𝑒𝑛(𝑠𝑡𝑟)≤1000 1≤。≤1000 ,元素大小满足 0≤𝑣𝑎𝑙≤100000 0≤。第三行输入一个整数0或1。输入整型数组和排序标识,对其元素按照升序或降序进行排序。​ 2.使用元素的内置比较器,max函数。数据范围: 1≤𝑛≤1000 1≤。

m0_57463864的博客 503

Spark中Application、Job、Stage和Task区别详解

在Spark中,有一些关键的概念,如Application、Job、Stage和Task,它们描述了Spark作业的不同层次和组成部分。下面我将详细介绍每个概念,并通过示例说明它们之间的区别。

优快云 精品推荐 907

深度学习工具包 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")

HJ101 输入整型数组和排序标识,对其元素按照升序或降序

reversed()是Python内置的一个函数,它返回一个反转的迭代器。如果你想要一个临时的反转列表,而不是创建一个新的列表,这个函数会非常有用。需要注意的是,reversed()返回的是一个迭代器,如果你需要列表形式的输出,可以将其转换为列表。数据范围: 1≤𝑛≤1000 1≤n≤1000 ,元素大小满足 0≤𝑣𝑎𝑙≤100000 0≤val≤100000。虽然这种方法相对繁琐,但在理解列表和循环的基础上,它可以帮助你更好地理解倒序列表的实现过程。这种特殊的切片方式来轻松地实现列表的倒序。

m0_54414851的博客 269

RU DOS版、EFI版32bit/64bit BIOS常用工具

DOS版、EFI版的RU工具,可用来查看IO、MEM、PCI、SMBIOS等资源。亲测在EFI SHELL下可用。

【牛客网 - 华为机试 - HJ101 输入整型数组和排序标识,对其元素按照升序或降序进行排序】

思路: step1:首先,第一行输入数组元素个数,转换为整型;第二行输入数组,用list(map())转换为整型;第三行传入参数s,也转换为整型; step2:如果 s==0 ,将num用sort()函数排序,默认正序排列;之后for循环,遍历排序后的num,输出打印,并用空格隔开; step3:如果 s==1,将num用sort()函数排序,倒序排列(reverse = True);之后for循环,遍历排序后的num,输出打印,并用空格隔开 代码如下: n = int(input()) n..

爱摸鱼的经济er的博客 1413

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

IMSL CNL 7.0.0 (x86-64)Crack

IMSL CNL 7.0.0 (x86-64)Crack intel的算法库破解文件,这是C++版本的破解文件

【java华为机试】HJ101 输入整型数组和排序标识,对其元素按照升序或降序进行排序

描述 输入整型数组和排序标识,对其元素按照升序或降序进行排序 数据范围: ,元素大小满足 输入描述: 第一行输入数组元素个数 第二行输入待排序的数组,每个数用空格隔开 第三行输入一个整数0或1。0代表升序排序,1代表降序排序 输出描述: 输出排好序的数字 import java.util.Scanner; public class Main { public static void main(String[] args) { // 第一行输入数组元素个数 // 第二行输入待...

一只小白 591

华为机试HJ101 输入整型数组和排序标识,对其元素按照升序或降序进行排序

首先看一下题。

bingw0114的博客 317

【华为机试】HJ101 输入整型数组和排序标识,对其元素按照升序或降序进行排序

描述 输入整型数组和排序标识,对其元素按照升序或降序进行排序 输入描述: 第一行输入数组元素个数 第二行输入待排序的数组,每个数用空格隔开 第三行输入一个整数0或1。0代表升序排序,1代表降序排序 输出描述: 输出排好序的数字 示例1 输入: 8 1 2 4 9 3 55 64 25 0 复制输出: 1 2 3 4 9 25 55 64 复制 示例2 输入: 5 1 2 3 4 5 1 输出: 5 4 3 2 1 ...

u012193374的博客 346

华为机试HJ101输入整型数组和排序标识,对其元素按照升序或降序进行排序

输入整型数组和排序标识,对其元素按照升序或降序进行排序。

qq_29787929的博客 242

HJ101 输入整型数组和排序标识,对其元素按照升序或降序进行排序(c++)

题目链接:输入整型数组和排序标识,对其元素按照升序或降序进行排序_牛客题霸_牛客网 注意点: 某个靓仔的vector排序讲的好:C++ vector容器的排序 (从小到大,从大到小)_Rosita.的博客-优快云博客_vector容器排序 #include <iostream> #include <vector> #include <algorithm> using namespace std; int main(){ int n; whi

欢迎光临我的博客! 467
上一篇: HJ72 百钱买百鸡问题
下一篇: HJ75 公共子串计算
sherryyang1234
博客等级 码龄10年 13粉丝 118原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值