2021荣耀秋招笔试代码题
生活随笔
收集整理的這篇文章主要介紹了
2021荣耀秋招笔试代码题
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
輸入描述:
一個ASCII字符串,該字符串沒有順序,字符可以重復,輸入字符串的長度<=30。
輸出描述:
一個新的字符串,該字符串中字符在輸入字符串中只出現一次,且該新字符串按照ASCII碼從小到大的順序排列。如果輸入字符串中字符出現的次數都是大于1,則無需輸出。
示例1:
輸入:efghabcd1234efgh
輸出:1234abcd
貼一下自己的代碼,僅供參考,不一定準確。
#include <bits/stdc++.h> using namespace std; class Solution { public:string test1(string Input){int hashmap[128] = {0};string res;for(int i = 0; i < Input.length(); ++i){hashmap[static_cast<int>(Input[i])]++;}for(int i = 0; i < 128; ++i){if(hashmap[i] == 1){res += static_cast<char>(i); }}return res; }string test2(string Input){int hashmap[128] = {0};string res;for(int i = 0; i < Input.length(); ++i){hashmap[Input[i] - '0']++;}for(int i = 0; i < 128; ++i){if(hashmap[i] == 1){res += i + '0'; }}return res; } };int main() {char temp;string Input;Solution MySolution;cin >> Input;cout << MySolution.test1(Input) << endl;cout << MySolution.test2(Input) << endl;return 0; }總結
以上是生活随笔為你收集整理的2021荣耀秋招笔试代码题的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ABB 机器人DH参数
- 下一篇: c语言算无限小数,随机算式的除法如果答案