10.15.2024刷华为OD C题型(二)

[复制链接]
发表于 2026-1-8 21:58:14 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
假如是目标院校150分能过,而且这道题是两百分的话我就阿弥陀佛了。
这类简朴范例的字符串处置惩罚标题一看就有思绪,最少能做,碰到那种稍微加点数学的,感觉直接GG。
以是说,不知道这种永无止境的测试对于个人的技能积累有什么意义,难度适中还行,假如难度大到肯定程度,就算是神仙也一样做不出来。
就算是荣幸过了,实操的时间,尚有很多的测验内容,不知道应该怎么去过,但至少这个东西先不消想。
以是重新明白目标就是至少每天欣赏十道标题,把简朴的标题思途经一遍,剩下的困难再说,至少把之前自己的代码本领先捡返来。
十道标题,做一下挑选分类,评定标题标难度。
我发现刷题这种东西根本没法停下哎,一停下来就会忘记很多东西,以是说好好复习吧。
这道智能效果表,我就先放在这里。来日诰日返来复习,也不知道AI天生的对不对。
暗码输入检测

这题做了半个钟,实在不难,就是细枝末节逐步摸返来,要是用上AI估计更快…以是前期可以慢,但是背面要 逐步加快速率。
1.遍历,留意字符串遍历会收缩,因此先用空格代替,背面再清除一遍
2.一个个判定,然后&&得出效果

  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4. string scanStr(string str);
  5. int main() {
  6.     string str = "ABC<c89%000<";
  7.     string result;
  8.     for (int i = 0; i < str.length(); ++i) {
  9.         if(str[i] == '<'){
  10.             if(i != 0){
  11.                 str[i] = ' ';
  12.                 str[i-1] = ' ';
  13.             }
  14.         }
  15.     }
  16.     for (char ch : str) {
  17.         if (!isspace(ch)) {
  18.             result += ch;
  19.         }
  20.     }
  21.     cout << result << ',';
  22.     //判断是否满足要求
  23.     bool a = false;
  24.     if(str.length() >= 8) a = true;
  25.     bool b = false;
  26.     for(int i = 0; i < str.length(); i++){
  27.         if(str[i] >='a'&& str[i] <='z')
  28.             b = true;
  29.             break;
  30.     }
  31.     bool c = false;
  32.     for(int i = 0; i < str.length(); i++){
  33.         if(str[i] >='A'&& str[i] <='Z')
  34.             c = true;
  35.             break;
  36.     }
  37.     bool d = false;
  38.     for(int i = 0; i < str.length(); i++){
  39.         if(str[i] >='0'&& str[i] <='9')
  40.             d = true;
  41.             break;
  42.     }
  43.     bool e = false;
  44.     for(int i = 0; i < str.length(); i++){
  45.         if(str[i] >='0'&& str[i] <='9' || str[i] >='a'&& str[i] <='z' || str[i] >='A'&& str[i] <='Z'){
  46.              continue;
  47.         }
  48.         else{
  49.             e = true;
  50.             break;
  51.         }
  52.     }
  53.     bool result1 = a && b && c && d &&e;
  54.     string res = result1 ? "true":"false";
  55.     cout<< res << endl;
  56.     return 0;
  57. }
复制代码
智能效果表

https://www.nowcoder.com/discuss/561941270055096320
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4. #include <algorithm>
  5. using namespace std;
  6. struct Student {
  7.     string name;
  8.     vector<int> scores;
  9. };
  10. bool compareStudents(const Student& a, const Student& b, const string& subject) {
  11.     if (subject.empty()) {
  12.         // 按总分排序
  13.         return accumulate(a.scores.begin(), a.scores.end(), 0) >
  14.                accumulate(b.scores.begin(), b.scores.end(), 0);
  15.     } else {
  16.         // 找到对应科目的索引
  17.         int index = find(a.scores.begin(), a.scores.end(), subject) - a.scores.begin();
  18.         return a.scores[index] > b.scores[index];
  19.     }
  20. }
  21. int main() {
  22.     int n, m;
  23.     cin >> n >> m;
  24.     vector<string> subjects(m);
  25.     for (int i = 0; i < m; i++) {
  26.         cin >> subjects[i];
  27.     }
  28.     vector<Student> students(n);
  29.     for (int i = 0; i < n; i++) {
  30.         cin >> students[i].name;
  31.         students[i].scores.resize(m);
  32.         for (int j = 0; j < m; j++) {
  33.             cin >> students[i].scores[j];
  34.         }
  35.     }
  36.     string sortSubject;
  37.     cin >> sortSubject;
  38.     // 根据指定科目或总分排序
  39.     sort(students.begin(), students.end(),
  40.          [&sortSubject](const Student& a, const Student& b) {
  41.              return compareStudents(a, b, sortSubject);
  42.          });
  43.     // 输出排序后的学生姓名
  44.     for (const auto& student : students) {
  45.         cout << student.name << " ";
  46.     }
  47.     cout << endl;
  48.     return 0;
  49. }
复制代码
回复

使用道具 举报

登录后关闭弹窗

登录参与点评抽奖  加入IT实名职场社区
去登录
快速回复 返回顶部 返回列表