Record 2017/9/7CVTE embedded software written test programming questions

1. Input a string, output the character with the least number of occurrences in the string, if there are repetitions, output the character with the most characters at the end, for example input: "abbccdffgg" output: d input: "aaabbbccddee" output: 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");
}

To sum up, I rarely use non-IDE environment for programming, causing push() to be written as push_back() fatal error. When doing questions, I always think about finishing it quickly, and I don’t have the usual calmness. When the logic is not too clear, I will start writing code,

2. I don't remember the second programming question very well, ID_SOUND_TP3110_maxhubs80H_12V8R10W, separate the useful data in the string.

#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");
}

There are only 30 minutes left to do this question. I was too panicked to write a rough outline. This method is the least efficient. I will find an optimization algorithm and come back to add it later;

The 20 multiple-choice questions of CVTE embedded software development are indefinite options. Due to the lack of solid basic knowledge, many multiple-choice questions were made into single-choice questions, which eventually led to the failure of the written test.

The road is a long way to go, and I will go up and down to search.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325861205&siteId=291194637