华为4.15笔试
难是不难,但是感觉逻辑比较复杂。我是非科班出身,写的也很复杂。做了两道,第三道没时间看了。
第一道 AC:
#华为笔试##华为##笔试题目#
第一道 AC:
#include <iostream> #include <string> #include <vector> #include <stack> #include <algorithm> using namespace std; int main(){ string all; while(cin >> all){ if(all.size() < 1){ cout << "error.0001" << endl; continue; } vector<string> names; int pre = 0; for(int i = 0; i <= all.size(); i++){ if(all[i] >= 'A' && all[i] <= 'Z'){ if(i == 0 || all[i-1] == ',') continue; else{ cout << "error.0001" << endl; break; } } if(i == 0 || all[i-1] == ','){ if(all[i] < 'A' || all[i] > 'Z'){ break; } } if(all[i] == ',' || all[i] == '\0'){ names.push_back(all.substr(pre, i-pre)); pre = i+1; continue; } if(all[i] < 'a' || all[i] > 'z'){ cout << "error.0001" << endl; break; } } if(names.size() < 1){ cout << "error.0001" << endl; continue; } sort(names.begin(), names.end()); int vote = 0; int cnt = 0; string rnt; string tmp = names[0]; for(int j = 0; j < names.size(); j++){ if(names[j] == tmp){ cnt++; } else{ tmp = names[j]; cnt = 1; } if(cnt > vote){ vote = cnt; rnt = names[j]; } } cout << rnt << endl; } return 0 ; }第二道 AC:
#include <iostream> #include <string> #include <vector> using namespace std; int main(){ string keyword; string inform; while(cin >> keyword >> inform){ vector<string> items; int pre = 0; for(int i = 0; i <= inform.size(); i++){ if(inform[i] == ']'){ items.push_back(inform.substr(pre, i-pre+1)); pre = i+2; } } if(items.size() < 1){ cout << "FAIL" << endl; continue; } vector<string> name; vector<string> addr; vector<string> mask; vector<string> val; for(int j = 0; j < items.size(); j++){ if(items[j].find("addr=") != items[j].npos){ int cnt = items[j].find("addr=") + 5; if(items[j][cnt] != '0') continue; if(items[j][cnt+1] == 'x' || items[j][cnt+1] == 'X'){ int start = cnt; for(; items[j][cnt] != ','; cnt++); addr.push_back(items[j].substr(start, cnt-start)); } else continue; } else continue; if(items[j].find("mask=") != items[j].npos){ int cnt = items[j].find("mask=") + 5; if(items[j][cnt] != '0') continue; if(items[j][cnt+1] == 'x' || items[j][cnt+1] == 'X'){ int start = cnt; for(; items[j][cnt] != ','; cnt++); mask.push_back(items[j].substr(start, cnt-start)); } else continue; } else continue; if(items[j].find("val=") != items[j].npos){ int cnt = items[j].find("val=") + 4; if(items[j][cnt] != '0') continue; if(items[j][cnt+1] == 'x' || items[j][cnt+1] == 'X'){ int start = cnt; for(; items[j][cnt] != ']'; cnt++); val.push_back(items[j].substr(start, cnt-start)); } else continue; } else continue; for(int k = 0; k < items[j].size(); k++){ if(items[j][k] == '['){ name.push_back(items[j].substr(0, k)); } } } bool has = false; for(int m = 0; m < name.size(); m++){ if(name[m] == keyword){ has = true; cout << addr[m] << " " << mask[m] << " " << val[m] << endl; } } if(has == false){ cout << "FAIL" << endl; continue; } } return 0; }
#华为笔试##华为##笔试题目#