• 华为机试题 简单错误记录


    简介

    恶心
    4、循环记录时,只以第一次出现的顺序为准,后面重复的不会更新它的出现时间,仍以第一次为准.
    浪费爷爷的时间.
    明明只有8个空间, 却按照从头开始查找.

    code

    #include <iostream>
    #include <string>
    #include <vector>
    #include <sstream>
    #include <algorithm>
    using namespace std;
    struct Error{
        string in;
        int line;
        int time;
    };
    string decomp(string filepath){
        int end_pos = filepath.size()-1;
        for(; end_pos >= 0; end_pos--){
            if(filepath[end_pos] == '\') break;
        }
        string file = filepath.substr(end_pos + 1, filepath.size() - end_pos - 1);
        if(file.size() > 16) file = file.substr(file.size()-16, 16);
        return file;
    }
    void dec(string in, string &out, int &line) {
        for(int i=0; i<in.size(); i++) {
            if(in[i] == ' ') {
                for(int j=i-1; j>=0; j--){
                    if(in[j] == '\') break;
                    if(out.size() >= 16) break;
                    out += in[j];
                }
                reverse(out.begin(), out.end());
                stringstream ss;
                string num = in.substr(i+1);
                ss << num;
                ss >> line;
                return;
            }
        }
        return;
    }
    int main() {
        string in;
        vector<Error> v(8, {"", -1, 1});
        string filepath; int length;
        int index = 0;
        while(cin >> filepath >> length) {
            string file = decomp(filepath);
            string s = file;
            int line = length;
            bool check = false;
            for(int i=0; i<8; i++){
                if(v[i].in == s && v[i].line == line){
                    v[i].time++;
                    check = true;
                    break;
                }
            }
            if(check) {
                continue;
            }else{
                v[index].in = s;
                v[index].line = line;
                v[index].time = 1;
                index++;
                index = index % 8;
            }
        }
        for(int i = index; i < 8; i++){
            if(v[i].line != -1)
                cout << v[i].in << " " << v[i].line << " " << v[i].time << std::endl;
        }
        for(int i = 0; i < index; i++){
            cout << v[i].in << " " << v[i].line << " " << v[i].time << std::endl;
        }
        return 0;
    }
    
    
    #include <iostream>
    #include <string>
    #include <vector>
    #include <sstream>
    #include <algorithm>
    #include <set>
    using namespace std;
    struct Error{
        string in;
        int line;
        int time;
    };
    string decomp(string filepath){
        int end_pos = filepath.size()-1;
        for(; end_pos >= 0; end_pos--){
            if(filepath[end_pos] == '\') break;
        }
        string file = filepath.substr(end_pos + 1, filepath.size() - end_pos - 1);
        if(file.size() > 16) file = file.substr(file.size()-16, 16);
        return file;
    }
    void dec(string in, string &out, int &line) {
        for(int i=0; i<in.size(); i++) {
            if(in[i] == ' ') {
                for(int j=i-1; j>=0; j--){
                    if(in[j] == '\') break;
                    if(out.size() >= 16) break;
                    out += in[j];
                }
                reverse(out.begin(), out.end());
                stringstream ss;
                string num = in.substr(i+1);
                ss << num;
                ss >> line;
                return;
            }
        }
        return;
    }
    int main() {
        string in;
        vector<Error> v(8, {"", -1, 1});
        string filepath; int length;
        set<string> dis;
        int index = 0;
        while(cin >> filepath >> length) {
            string file = decomp(filepath);
            string s = file;
            int line = length;
            bool check = false;
            
            for(int i=0; i<8; i++){
                if(v[i].in == s && v[i].line == line){
                    v[i].time++;
                    check = true;
                    break;
                }
            }
            if(check) {
                continue;
            }else{
                if(dis.find(file + " " + to_string(line)) != dis.end()) {
                    continue;
                }
                v[index].in = s;
                v[index].line = line;
                v[index].time = 1;
                index++;
                index = index % 8;
            }
            dis.insert(file + " " + to_string(line));
        }
        for(int i = index; i < 8; i++){
            if(v[i].line != -1)
                cout << v[i].in << " " << v[i].line << " " << v[i].time << std::endl;
        }
        for(int i = 0; i < index; i++){
            cout << v[i].in << " " << v[i].line << " " << v[i].time << std::endl;
        }
        return 0;
    }
    
    Hope is a good thing,maybe the best of things,and no good thing ever dies.----------- Andy Dufresne
  • 相关阅读:
    Mac下各种编程环境的配置问题(python java)
    hackintosh和windows时区问题
    CAN波特率计算公式
    Jetson nano 安装 TensorFlow
    python逻辑运算符优先级
    CSS知识点(一)
    HTML标签(二)
    python2与python3的区别
    HTML标签(一)
    IO多路复用和协程
  • 原文地址:https://www.cnblogs.com/eat-too-much/p/14928807.html
Copyright © 2020-2023  润新知