华为2018年秋招试题AC

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/zh1204190329/article/details/82430760

1、26进制大数相加
这里写图片描述

这里写图片描述

#include <iostream>
#include <string>
#include <cstdio>
#include <string.h>

using namespace std;

int main()
{
    string str1,str2;
    cin >> str1 >> str2;

    int num1[200] = {0};
    int num2[200] = {0};
    int sum[200] = {0};
    int len1 = str1.size();
    int len2 = str2.size();

    int cnt1 = 0, cnt2 = 0;

    for (int i = len1 - 1; i >= 0; i--)
    {
        num1[++cnt1] = str1[i] - 'a';

    }

    for (int i = len2 - 1; i >= 0; i--)
    {
        num2[++cnt2] = str2[i] - 'a';

    }

    if (len1 > len2)
    {
        for (int i = 1; i <= len1; i++)
        {
            sum[i] = num1[i] + num2[i];
        }
    }
    else
    {
        for (int i = 1; i <= len2; i++)
        {
            sum[i] = num1[i] + num2[i];

        }
    }


    int cnt = 0;
    if (len1 >= len2)
    {
        for (int i = 1; i <= len1; i++)
        {
            sum[i+1] += sum[i]/26;
            sum[i] %= 26;
            ++cnt;
        }
        if (sum[len1+1])
        { ++cnt; }
    }
    else
    {
        for (int i = 1; i <= len2; i++)
        {
            sum[i+1] += sum[i]/26;
            sum[i] %= 26;
            ++cnt;
        }
        if (sum[len2+1])
        { ++cnt; }
    }


    for (int i = cnt; i >= 1; i--)
    { printf("%c",sum[i] + 'a'); }

    return 0;
}

2、判断字符串2中的字符是否都包含在字符串1中
这里写图片描述

这里写图片描述

#include <iostream>
#include <string>
#include <cstdio>
#include <string.h>

using namespace std;

int main()
{
    string str1,str2;
    cin >> str1 >> str2;

    int len1 = str1.size();
    int len2 = str2.size();

    if (len2 > len1 || len1 < 5 || len2 < 5)
        cout << "false";

    int flag = 1;
    for (int i = 0; i < len2; i++)
    {
        char tmp = str2[i];
        if (str1.find(tmp) == string::npos)
        {
            flag = 0;
            cout << "false";
            break;
        }

    }
    if (flag)
        cout << "true";

    return 0;
}

猜你喜欢

转载自blog.csdn.net/zh1204190329/article/details/82430760