记录2017/9/7CVTE嵌入式软件笔试编程题

来源:互联网 发布:js中创建数组 编辑:程序博客网 时间:2024/05/24 00:08

1.输入一个字符串,输出字符串中最后出现次数最少的字符,如果都有重复,则输出最后出现字符最多的字符,例如输入:“abbccdffgg”输出:d 输入:“aaabbbccddee”输出:b

#include <iostream>#include <stack>#include <vector>#include <queue>#include <string>using namespace std;stack<char> min_ch, max_ch;bool select_ch(char *s1){    if (s1==NULL)    {        return 0;    }    char *temp = s1;    int flag = 1;    while (*temp!='\0')    {        if (*temp!=*(temp+1))        {            min_ch.push(*temp);//入栈            temp = temp + 1;            continue;        }        int count = 1;        while (*temp==*(temp+1))        {            count++;            temp = temp + 1;        }        if (count>=flag)        {            for (int i = 0; i < count; i++)            {                max_ch.push(*temp);            }            flag = count;        }        temp = temp + 1;    }}void main(){    char *s1 = "abbccdffgg";    char *s2 = "aaabbbccddee";    select_ch(s1);    while (!min_ch.empty())    {        cout << min_ch.top() << endl;        min_ch.pop();    }    while (!max_ch.empty())    {        cout << max_ch.top() << endl;        max_ch.pop();    }    system("pause");}

总结,平时很少使用非IDE环境编程,造成push()写成了push_back()致命的错误,在做题的时候总想着快点做完没有平时的冷静,在逻辑不是太清晰的情况下就开始写代码,

2.第二个编程题记得不太清楚,ID_SOUND_TP3110_maxhubs80H_12V8R10W,分离出字符串中有用的数据.

#include <iostream>#include <stack>#include <vector>#include <queue>#include <string>using namespace std;struct pro_info{    char name_p[30];    char name_q[30];    int voltage;    int resistance;    int power;};vector<char *>temp;bool string_info(char *s1,pro_info* info){    if (s1==NULL)    {        return false;    }    char *next = s1;    while (*next!='\0')//取出分隔符    {        if (*next=='_')        {            temp.push_back(next);        }        next = next + 1;    }    //取出第一个name    char *p1 = temp[1];    int i = 0;    while (p1!=temp[2])    {        p1 = p1 + 1;        info->name_p[i++] = *(p1);    }    info->name_p[--i] = '\0';    //取出第二个name    p1 = temp[2];    i = 0;    while (p1!=temp[3])    {        p1 = p1 + 1;        info->name_q[i++] = *(p1);    }    info->name_q[--i] = '\0';    //取出    voltage;    p1 = temp[3];    int vol = 0;    while (*(p1+1)!='V')    {        p1 = p1 + 1;        vol = vol * 10 + ((*p1) - '0');    }    info->voltage = vol;    //取出 resistance;    int res = 0;    p1 = p1 + 1;    while (*(p1 + 1) != 'R')    {        p1 = p1 + 1;        res = res * 10 + ((*p1) - '0');    }    info->resistance = res;    //取出 power;    int pow = 0;    p1 = p1 + 1;    while (*(p1 + 1) != 'W')    {        p1 = p1 + 1;        pow = pow * 10 + ((*p1) - '0');    }    info->power = pow;    return true;}void main(){    char *s1 = "ID_SOUND_TP3110_maxhubs80H_12V8R10W";    struct pro_info* info=new struct pro_info;    string_info(s1,info);    cout << info->name_p << endl;    cout << info->name_q << endl;    cout << info->voltage << endl;    cout << info->resistance << endl;    cout << info->power << endl;    system("pause");}

在做这道题的时候时间只剩30分钟,太慌了写了个大概,这种方法算是效率最低的了吧,以后找到优化算法在回来补充;

CVTE嵌入式软件开发的20道选择题为不定选项,由于基础知识不扎实,好多多选做成了单选,最后导致笔试失败。

路漫漫其修远兮,吾将上下而求索.

原创粉丝点击