1.虎牙直播2019秋招編程題
阿新 • • 發佈:2018-09-07
span system http ring ret 第一題 pre png string
第一題:
#include <iostream> #include <string> using namespace std; bool IsVoChar(char c) { return (c == ‘a‘) || (c == ‘e‘) || (c == ‘o‘) || (c == ‘i‘) || (c == ‘u‘) || (c == ‘A‘) || (c == ‘E‘) || (c == ‘O‘) || (c == ‘I‘) || (c == ‘U‘); } string reverseVoChar(string s) {int slen = s.length(); for (int l = 0, r = slen - 1; l < r; ++l) { if (IsVoChar(s[l])) { while ((l < r) && !IsVoChar(s[r])) --r; swap(s[l], s[r--]); } } return s; } int main() { string str1, str2; cin>> str1; str2 = reverseVoChar(str1); cout << str2 << endl; system("pause"); return 0; }
第二題:
第三題:
#include <iostream> #include <sstream> using namespace std; string DelChar(string str) //從字符串中提取出數字,剔除掉字母 { for (int i = 0; i < str.length();) {int temp = (int)str[i]; if (temp >= 48 && temp <= 57) { i++; continue; } else { str.erase(i, 1); continue; } } return str; } string DecToHex(string str) //將字符串轉化為十六進制 { int i = 0; string result = ""; i++; int n = 0; for (int i = str.length() - 1, j = 1; i >= 0; i--) { n += (str[i] - ‘0‘) * j; j *= 10; } char _16[] = { ‘0‘, ‘1‘, ‘2‘, ‘3‘, ‘4‘, ‘5‘, ‘6‘, ‘7‘, ‘8‘, ‘9‘, ‘A‘, ‘B‘, ‘C‘, ‘D‘, ‘E‘, ‘F‘ }; const int radix = 16; while (n) { int i = n % radix; result = _16[i] + result; n /= radix; } return result; } int main() { string str1, str2; cin >> str1; str1 = DelChar(str1); //cout << str1 << endl; str2 = DecToHex(str1); cout << str2 << endl; system("pause"); return 0; }
1.虎牙直播2019秋招編程題