V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
• 请不要在回答技术问题时复制粘贴 AI 生成的内容
angelcstt
V2EX  ›  程序员

各位大佬帮忙做个菊花的笔试题,感谢

  •  
  •   angelcstt · Aug 7, 2019 · 4110 views
    This topic created in 2459 days ago, the information mentioned may be changed or developed.

    RT

    https://i.loli.net/2019/08/07/gS95mI8nbZBX4ha.jpg

    感谢

    18 replies    2019-08-08 11:17:37 +08:00
    angelcstt
        1
    angelcstt  
    OP
       Aug 7, 2019
    大佬在哪里 求助大佬啊 有偿都可以
    msaionyc
        3
    msaionyc  
       Aug 7, 2019
    你题目给完整了吗
    angelcstt
        4
    angelcstt  
    OP
       Aug 7, 2019
    @msaionyc 大佬等我拍完整
    wateryessence
        5
    wateryessence  
       Aug 7, 2019
    牛客网问去
    angelcstt
        6
    angelcstt  
    OP
       Aug 7, 2019
    第一题 @msaionyc ~

    https://i.loli.net (外链)/2019/08/07/gS95mI8nbZBX4ha.jpg
    https://imgchr.com/i/eII5 (外链) GT
    lxy42
        7
    lxy42  
       Aug 7, 2019 via Android
    第一题没拍全吧,估计考查的是中缀后缀表达式。
    angelcstt
        8
    angelcstt  
    OP
       Aug 7, 2019 via iPhone
    @lxy42 第一题下面补充了大佬
    brainfxxk
        9
    brainfxxk  
       Aug 7, 2019
    第一个表达式求值 第二个字符串处理...
    lxy42
        10
    lxy42  
       Aug 7, 2019 via Android
    第二题用一个长度为 26 的数组表示字符集,数组元素值等于对应字符的个数。两个数组相减就是结果。
    Leigg
        11
    Leigg  
       Aug 7, 2019 via Android
    能不能换个图床,这个很渣
    angelcstt
        12
    angelcstt  
    OP
       Aug 7, 2019 via iPhone
    @Leigg 提交了,谢谢啦
    angelcstt
        13
    angelcstt  
    OP
       Aug 7, 2019 via iPhone
    @lxy42 谢谢啦
    wangkai0351
        14
    wangkai0351  
       Aug 7, 2019
    #include <iostream>
    #include <string>
    #include <map>
    #include <vector>
    #include <sstream>
    #include <string.h>
    using namespace std;

    vector<string> split(const string &str,const string &pattern)
    {
    //const char* convert to char*
    char * strc = new char[strlen(str.c_str())+1];
    strcpy(strc, str.c_str());
    vector<string> resultVec;
    char* tmpStr = strtok(strc, pattern.c_str());
    while (tmpStr != NULL)
    {
    resultVec.push_back(string(tmpStr));
    tmpStr = strtok(NULL, pattern.c_str());
    }

    delete[] strc;

    return resultVec;
    }

    int main(void)
    {
    string s;
    while(cin>>s)
    {
    string s1;
    string s2;
    size_t at_pos = s.find('@');
    //cout << "at_pos = " << at_pos << endl;
    if(at_pos == s.size()-1)
    {
    for (int i = 0; i < s.size()-1; ++i) {
    cout << s[i];
    }
    cout << endl;
    break;
    }
    else
    {
    s1 = s.substr(0,at_pos);
    s2 = s.substr(at_pos+1,s.size());
    //cout << s1 << endl;
    //cout << s2 << endl;
    }
    //分别处理 s1,s2
    map<char,int> um1;
    map<char,int> um2;
    //s1 按照逗号分割
    vector<string> v1;
    v1 = split(s1,",");
    for(auto e:v1)
    {
    int i;
    char c;
    char c_;
    stringstream ss(e);
    ss >> c >> c_ >> i;
    //cout << "c = " << c << " i = " << i << endl;
    um1[c] = i;
    }
    //s2 按照逗号分割
    vector<string> v2;
    v2 = split(s2,",");
    for(auto e:v2)
    {
    int i;
    char c;
    char c_;
    stringstream ss(e);
    ss >> c >> c_ >> i;
    //cout << "c = " << c << " i = " << i << endl;
    um2[c] = i;
    }
    string res;
    for(auto e:um1)
    {
    res += e.first;
    res += ":";
    res += to_string(e.second-um2[e.first]);
    res += ",";
    }
    for (int j = 0; j < res.size()-1; ++j) {
    cout << res[j];
    }
    cout << endl;
    }
    return 0;
    }
    //a:3,b:5,c:1@
    //a:3,b:5,c:2@a:1,b:2
    wangkai0351
        15
    wangkai0351  
       Aug 7, 2019
    zhoudaiyu
        16
    zhoudaiyu  
    PRO
       Aug 7, 2019
    我来发个第一题的,不知道能不能用 Py 实现
    def get_result(given_string):
    return eval((" ".join([items for items in given_string]).replace("1", "True").replace("0", "False").replace("!", "not").replace("&", "and").replace("|", "or")))
    Mountain
        17
    Mountain  
       Aug 8, 2019 via iPhone
    公然求助场外观众了?
    summer20100514
        18
    summer20100514  
       Aug 8, 2019
    完善拉黑列表
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2568 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 89ms · UTC 06:54 · PVG 14:54 · LAX 23:54 · JFK 02:54
    ♥ Do have faith in what you're doing.