华为机考模拟题

2023-11-13

 一、字符串平均重量

 


// we have defined the necessary header files here for this problem.
// If additional header files are needed in your program, please import here.

int main()
{
    // please define the C++ input here. For example: int a,b; cin>>a>>b;;
    // please finish the function body here.
    // please define the C++ output here. For example:cout<<____<<endl;
    double total;
    int strNum=0;
    string str;
    while(cin>>str){
        strNum++;
        total+=str.size();
    }
    printf("%.2f",total/strNum);
    return 0;
}

二、solo习惯


// we have defined the necessary header files here for this problem.
// If additional header files are needed in your program, please import here.

int main()
{
    // please define the C++ input here. For example: int a,b; cin>>a>>b;;
    // please finish the function body here.
    // please define the C++ output here. For example:cout<<____<<endl;
    string str;
    getline(cin,str);
    for(int i=0;i<str.size();i++){
        if(str[i]=='a'||str[i]=='e'||str[i]=='i'||str[i]=='o'||str[i]=='u'){
            str[i]=str[i]-('a'-'A');
        }else if(str[i]=='A'||str[i]=='E'||str[i]=='I'||str[i]=='O'||str[i]=='U'||str[i]==' '){
           continue;
        }else if(str[i]>='A'&&str[i]<='Z'){
            str[i]=str[i]+('a'-'A'); 
        }
    }
    cout<<str<<endl;
    return 0;
}

三、计算字符串重新排列数

 

 完成67%

#include<algorithm>
#include<string.h>
#include<iostream>
// we have defined the necessary header files here FOR this problem.
// IF additional header files are needed IN your program, please IMPORT here.
int main()
{
    // please define the C input here. FOR EXAMPLE: int n; scanf("%d",&n);
    // please finish the FUNCTION body here.
    // please define the C output here. FOR EXAMPLE: printf("%d",a);
    char num[9];
    cin>>num;
    int n = strlen(num);
    int result=0;
    sort(num,num+n);
    do
    {
     //for(int i=0;i<n;i++){
     //   cout<<num[i]<<" ";
     //   cout<<endl;
     //}
     result++;
    }while(next_permutation(num,num+n));
    
    cout<<result<<endl;
    return 0;
}

 完成97%

//#include <iostream>
//#include <cstring>
// we have defined the necessary header files here for this problem.
// If additional header files are needed in your program, please import here.
#include<set>
using namespace std;
void AllPermutation(string perm, int from, int to);
int num=0;
set<string> sets;
int main()
{
    // please define the C++ input here. For example: int a,b; cin>>a>>b;;
    // please finish the function body here.
    // please define the C++ output here. For example:cout<<____<<endl;
    string str;
    getline(cin,str);
    AllPermutation(str, 0, str.size()-1);
    cout<<sets.size()<<endl;
    return 0;
}


void AllPermutation(string perm, int from, int to)
{
    if(from > to)
        return;
            
    if(from == to)     //打印当前排列 
    {	
        static int count = 1;    //局部静态变量,用来统计全排列的个数  
        num=count;
        count++;
        sets.insert(perm);
		//cout << count++ << ":" << perm;
        //cout << endl;
    }
    if(from < to)     //用递归实现全排列 
    {
        for(int j = from; j <= to; j++)    //第j个字符分别与它后面的字符交换就能得到新的排列
        {
                swap(perm[j], perm[from]);
            //cout<<0;
            AllPermutation(perm, from + 1, to);
            //cout<<1;
            swap(perm[j], perm[from]);
            //cout<<2;
            
        }
    }
}

100% 


// we have defined the necessary header files here for this problem.
// If additional header files are needed in your program, please import here.
#include<iostream>
#include<algorithm>

using namespace std;

int main()
{
    // please define the C++ input here. For example: int a,b; cin>>a>>b;;
    // please finish the function body here.
    // please define the C++ output here. For example:cout<<____<<endl;

    string str;
    int count=0;
    getline(cin,str);
    //没有sort好像不行
    sort(str.begin(),str.end());
	do{
		//cout<<str<<endl;
		count++;
	}while(next_permutation(str.begin(),str.end()));
    
    cout<<count<<endl;
    return 0;
}



本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

华为机考模拟题 的相关文章

随机推荐

  • 输出具有n个结点的所有不同的二叉树-增强前序遍历形式输出-C++

    我们知道具有n个结点的不同的二叉树的数量是个 这是一个卡塔兰数 那么如何确定这些二叉树是什么样子的呢 下面是博主的思路 我们还知道一个入栈序列的不同出栈序列的数量也是个 于是博主就想 这不是巧了么 既然他们的数量是一样的 而且均不相同 那么
  • unity 控制物体旋转的角度

    using System Collections using System Collections Generic using UnityEngine public class Main MonoBehaviour public float
  • 为“广东数字工商”保驾护航——Apusic应用服务器在广东省工商局的应用

    互联网经济时代 信息技术的变革改变了人们传统的工作 学习 生活和娱乐方式 同时对工商部门的信息化建设提出了挑战 如何利用信息技术改进工商工作 形成新的工作方式 已成为工商系统所关心的问题 数字工商 的提出 便是其中的佐证之一 数字工商 是指
  • 从ping和ping6说起

    1 Windows中的ping ping6 发送ICMP ECHO REQUEST到网络主机 ping6是ICMPv6版的ping实现 t 不停地ping指定的主机 要查看统计信息并继续ping 按Ctl Break 要停止按Ctl C a
  • 垂直广告是什么意思_广告新趋势——内容为王 垂直细分

    广告的变革 曾经的广告投放四大媒介 电视 报纸 杂志 广播 在如今看来早已式微 除了曝光率特别高的综艺节目 影视剧 电影等大屏幕广告以外 其余资源的广告部门或者传统广告代理公司都在纷纷转型 媒体结构变革也意味着广告形式的变革 作为经历传统广
  • 如何配置Git工具

    安装Git 首先确保你已经在计算机上安装了Git 你可以从Git官方网站Git Downloads git scm com 配置用户信息 在命令行终端中 使用下面的命令来配置你的用户名和电子邮件地址 git config global us
  • 如何快速找到paper 提到算法的源码(计算机领域)??

    1 如果该算法有开源的话 首先推荐网站 https paperswithcode com 比较高效 不需要VPN 2 如果算法比较新的话 最好去作者的主页 大佬 去逛一下 3 使用Google 搜索 paper 名字 source code
  • Spring Boot注入Servlet、Filter、Listener 注解方式和使用RegistrationBean二种方式 加源码分析

    目录 Spring Boot 注入Servlet Filter Listener 官方文档 基本介绍 应用实例1 使用注解方式注入 创建 Servlet java 修改Application java 加入 ServletComponent
  • MacBook M1 安装配置conda与python3.9注意事项

    macOS 版本 1 python 3 9 才支持m1 所以需要下载3 9之上的版本 https www python org downloads macos 2 如果需要安装Anaconda 可省略单独安装python anaconda自
  • 苹果CMS V10 后台一键采集豆瓣API获取资料(最新版)

    进入苹果CMS根目录后 找到如下文件 application admin view vod info html 大约在718行左右 照图修改两处位置即可 同时列出关键代码如下 修改后一键采集入库资料示例 相关AJAX请求核心代码如下 aja
  • 元宇宙(四)人机接口

    1 VR AR MR 现在的VR AR MR一定程度上试图解决把虚拟世界 展示 给我们的问题 先不说效果如何 这个接口的也只能提供视觉和听觉信息 虽然视觉和听觉为我们提供了大部分信息量 但其它感知能力 触觉 嗅觉 味觉也虚拟世界能让我们有真
  • 华为实习生2022机考、技术面及主管面试

    第一题 第一种情况 a坐标比b坐标小 a的坐标更新为b 1 第二种情况 a坐标比b坐标大 直接加1 对于B来说也是一样 按照这个原则来更新坐标 最后返回即可 第二题 动态规划求地图障碍物的题 不同路径https leetcode cn pr
  • Linux 网络管理

    网络管理 1 网卡命名方式 1 1 网卡名称的组成格式 前两个字母标识固件 以太网卡以 en 开头 无线网卡以 wl 开头 后一个字母标识设备结构 o 主板上集成的设备的设备索引号 s 扩展槽的索引号 p s 基于拓扑的命名 如enp2s1
  • 【使用 BERT 的问答系统】第 1 章 : 自然语言处理简介

    大家好 我是Sonhhxg 柒 希望你看完之后 能对你有所帮助 不足请指正 共同学习交流 个人主页 Sonhhxg 柒的博客 CSDN博客 欢迎各位 点赞 收藏 留言 系列专栏 机器学习 ML 自然语言处理 NLP 深度学习 DL fore
  • 类模板的使用

    模板类和静态成员 include
  • GUID字符串做主键与Number类型做主键 的执行效率比较

    使用GUID字符串做主键与Number类型做主键 在数据量不太多的时候 如 少于2 万条 查询 插入效率差别几乎可以忽略不计 但在磁盘空间占用方面差别比较明显 对主键的检索完全走的index 检索的次数和采用number的主键理论应该一样
  • S7-200 PLC的CPU模块介绍

    更多关于西门子S7 200PLC内容查看 西门子200系列PLC学习课程大纲 课程筹备中 1 什么是西门子200PLC的CPU 如下图1 1所示 S7 200 PLC CUP是将一个微处理器 一个集成电源 一定的数字量或模拟量I O 一定的
  • 一、markdown 常见公式

    文章目录 公式 字符 希腊字符 三角 对数 指数函数 向量 矩阵 省略号 空格 运算符 累加累积 开方 极限 导数 微积分 括号 绝对值 范数 分段 逻辑运算符 集合运算符 箭头 上下标符 公式 字符 希腊字符 字符 Markdown 字符
  • CSP-J (NOIP普及组) 历年复赛真题考察内容(1998~2021)

    TZOJ题目分类 本博客原文地址 https www cnblogs com BobHuang p 14522022 html 其中 1 较简单题26题左右 2 动态规划17题 其中9题较好做 3 模拟 阅读题目将问题抽象建模写出程序 为1
  • 华为机考模拟题

    一 字符串平均重量 we have defined the necessary header files here for this problem If additional header files are needed in your