马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
假如是目标院校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;
- }
复制代码 |