美文网首页
网易笔试题-时钟,会话列表,字符阵

网易笔试题-时钟,会话列表,字符阵

作者: tingjieee_19e5 | 来源:发表于2018-08-03 23:06 被阅读0次
    image.png
    
    #include <iostream>
    #include <string>
    #include <string.h>
    #include <vector>
    using namespace std;
     
    void modify(string time){
        int hh = 0,mm = 0,ss = 0;
        hh += (time[0]-'0')*10;
        hh += (time[1]-'0');
        mm += (time[3]-'0')*10;
        mm += (time[4]-'0');
        ss += (time[6]-'0')*10;
        ss += (time[7]-'0');
        //cout << hh << ":" << mm << ":" << ss << endl;
        if(hh > 23)
            hh = hh % 10;
        if(mm > 59)
            mm = mm % 10;
        if(ss > 59)
            ss = ss % 10;
        char t[10];
        t[0] = (hh / 10) + '0';
        t[1] = (hh % 10) + '0';
        t[2] = ':';
        t[3] = (mm / 10) + '0';
        t[4] = (mm % 10) + '0';
        t[5] = ':';
        t[6] = (ss / 10) + '0';
        t[7] = (ss % 10) + '0';
        t[8] = '\0';
        cout << t << endl;
    }
     
    int main()
    {
        int T;
        cin >> T;
        vector<string> lines;
        //char line[100][10];
        for(int i = 0;i < T;++i){
            string time;
            //char time[10];
            cin >> time;
            lines.push_back(time);
            modify(time);
        }
     
        return 0;
    }
    
    image.png
    #include <iostream>
    #include <string>
    #include <string.h>
    #include <vector>
    #include <set>
    using namespace std;
     
    int main()
    {
        int T;
        cin >> T;
        for(int i = 0; i < T;++i){
            int N;
            cin >> N;
            vector<long> ids;
            for(int i = 0; i < N;++i){
                long id;
                cin >> id;
                ids.push_back(id);
            }
            vector<long> idlist;
            set<long> check;
            for(int i = N-1;i >= 0;--i){
                if(check.find(ids[i]) == check.end()){
                    check.insert(ids[i]);
                    idlist.push_back(ids[i]);
                }
            }
            for(size_t i = 0; i < idlist.size()-1;++i){
                cout << idlist[i] << " ";
            }
            cout << idlist[idlist.size()-1] << endl;
        }
     
        return 0;
    }
    
    image.png
    #include <iostream>
    #include <string.h>
     
    using namespace std;
    char charArray[100][100];
     
    int main()
    {
        int T;
        cin >> T;
        for(int i = 0; i < T;++i){
            int row,col;
            cin >> row >> col;
            for(int j = 0; j < row;++j){
                memset(charArray[j], 0, 100*sizeof(char));
                cin >> charArray[j];
            }
            char target[10];
            cin >> target;
            int targetLength = strlen(target);
            //cout << targetLength << endl;
            int cnt = 0;
            for(int _i = 0; _i < row;++_i){
                for(int _j = 0; _j < col;++_j){
                    if(charArray[_i][_j] == target[0]){
                            //检查横着的
                        int _k = 1;
                        for(;_k < targetLength;++_k){
                            if(!((_j+_k  < col) && (charArray[_i][_j+_k] == target[_k])))
                                break;
                        }
                        if(_k == targetLength){
                            ++cnt;
                            //cout << _i <<" , " << _j << endl;
                        }
                            //检查竖着的
                        for(_k = 1;_k < targetLength;++_k){
                            if(!((_i+_k  < row) && (charArray[_i+_k][_j] == target[_k])))
                                break;
                        }
                        if(_k == targetLength)
                            ++cnt;
                            //检查右下
                        for(_k = 1;_k < targetLength;++_k){
                            if(!((_j+_k  < col) && (_i+_k  < row) && charArray[_i+_k][_j+_k] == target[_k]))
                                break;
                        }
                        if(_k == targetLength)
                            ++cnt;
                    }
                }
            }
            cout << cnt << endl;
        }
     
        return 0;
    }
    

    相关文章

      网友评论

          本文标题:网易笔试题-时钟,会话列表,字符阵

          本文链接:https://www.haomeiwen.com/subject/cmqpvftx.html