当前位置: 首页 > article >正文

10.15.2024刷华为OD C题型(二)

10.15.2024刷华为OD C题型(二)

  • 密码输入检测
  • 智能成绩表

如果是目标院校150分能过,而且这道题是两百分的话我就阿弥陀佛了。
这类简单类型的字符串处理题目一看就有思路,起码能做,遇到那种稍微加点数学的,感觉直接GG。
所以说,不知道这种永无止境的测试对于个人的技术积累有什么意义,难度适中还行,如果难度大到一定程度,就算是神仙也一样做不出来。
就算是侥幸过了,实操的时候,还有很多的考试内容,不知道应该怎么去过,但至少这个东西先不用想。
所以重新明确目标就是 至少每天浏览十道题目,把简单的题目思路过一遍,剩下的难题再说,至少把之前自己的代码能力先捡回来。
十道题目,做一下挑选分类,评定题目的难度。

我发现刷题这种东西根本没法停下哎,一停下来就会忘记很多东西,所以说好好复习吧。
这道智能成绩表,我就先放在这里。明天回来复习,也不知道AI生成的对不对。

密码输入检测

这题做了半个钟,其实不难,就是细枝末节慢慢摸回来,要是用上AI估计更快…所以前期可以慢,但是后面要 慢慢加快速度。
1.遍历,注意字符串遍历会缩短,因此先用空格代替,后面再排除一遍
2.一个个判断,然后&&得出结果
在这里插入图片描述

#include <iostream>
#include <string>
using namespace std;

string scanStr(string str);
int main() {
    string str = "ABC<c89%000<";
    string result;
    for (int i = 0; i < str.length(); ++i) {
        if(str[i] == '<'){
            if(i != 0){
                str[i] = ' ';
                str[i-1] = ' ';
            }
        }
    }
    for (char ch : str) {
        if (!isspace(ch)) {
            result += ch;
        }
    }
    cout << result << ',';

    //判断是否满足要求
    bool a = false;
    if(str.length() >= 8) a = true;
    bool b = false;
    for(int i = 0; i < str.length(); i++){
        if(str[i] >='a'&& str[i] <='z')
            b = true;
            break;
    }
    bool c = false;
    for(int i = 0; i < str.length(); i++){
        if(str[i] >='A'&& str[i] <='Z')
            c = true;
            break;
    }
    bool d = false;
    for(int i = 0; i < str.length(); i++){
        if(str[i] >='0'&& str[i] <='9')
            d = true;
            break;
    }
    bool e = false;
    for(int i = 0; i < str.length(); i++){
        if(str[i] >='0'&& str[i] <='9' || str[i] >='a'&& str[i] <='z' || str[i] >='A'&& str[i] <='Z'){
             continue;
        }
        else{
            e = true;
            break;
        }
    }

    bool result1 = a && b && c && d &&e;
    string res = result1 ? "true":"false";
    cout<< res << endl;


    return 0;
}


智能成绩表

https://www.nowcoder.com/discuss/561941270055096320

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

struct Student {
    string name;
    vector<int> scores;
};

bool compareStudents(const Student& a, const Student& b, const string& subject) {
    if (subject.empty()) {
        // 按总分排序
        return accumulate(a.scores.begin(), a.scores.end(), 0) >
               accumulate(b.scores.begin(), b.scores.end(), 0);
    } else {
        // 找到对应科目的索引
        int index = find(a.scores.begin(), a.scores.end(), subject) - a.scores.begin();
        return a.scores[index] > b.scores[index];
    }
}

int main() {
    int n, m;
    cin >> n >> m;

    vector<string> subjects(m);
    for (int i = 0; i < m; i++) {
        cin >> subjects[i];
    }

    vector<Student> students(n);
    for (int i = 0; i < n; i++) {
        cin >> students[i].name;
        students[i].scores.resize(m);
        for (int j = 0; j < m; j++) {
            cin >> students[i].scores[j];
        }
    }

    string sortSubject;
    cin >> sortSubject;

    // 根据指定科目或总分排序
    sort(students.begin(), students.end(),
         [&sortSubject](const Student& a, const Student& b) {
             return compareStudents(a, b, sortSubject);
         });

    // 输出排序后的学生姓名
    for (const auto& student : students) {
        cout << student.name << " ";
    }
    cout << endl;

    return 0;
}

http://www.kler.cn/news/355287.html

相关文章:

  • 怎么一键下载网页所有图片?3个方法轻松搞定
  • 论文笔记:D-vlog 用于抑郁症检测的多模态数据集
  • 智慧园区能带来哪些便利?
  • 基于SpringBoot+Vue+uniapp微信小程序的婚庆摄影小程序的详细设计和实现(源码+lw+部署文档+讲解等)
  • CentOS 7- 配置阿里镜像源
  • HTML_文本标签
  • MySQL【知识改变命运】05
  • 计数型信号量
  • 【C语言】函数指针
  • 什么是ERP?快速理解ERP系统与ERP软件的区别
  • Python 数值计算与数值分析基础
  • 拿到snp的rawdata后如何使用GATK进行筛选(GATK硬筛选文档翻译)
  • 基于BERT的语义分析实现(论文复现)
  • 51单片机的超声波视力保护仪【proteus仿真+程序+报告+原理图+演示视频】
  • PCL 点云配准-4PCS算法(粗配准)
  • Tbox编译注意问题
  • java基于SpringBoot+Vue+uniapp微信小程序的自助点餐系统的详细设计和实现(源码+lw+部署文档+讲解等)
  • 基于Springboot+Vue的宠物援助平台(含源码+数据库)
  • 【编程语言】Kotlin快速入门 - 集合与Lambda
  • 删除 Word 空白页的 3 种方法总结