网易雷火8.14游戏研发笔试
做了1.15道,太恶心了
第一题解密,100%
第二题字符串染色,15%,扣了2个多小时,就是不知道错哪了,我是废物😪😪
第一题 #include <iostream> #include <vector> #include <algorithm> #include <string> using namespace std; bool is_valid_ascii(vector<int> num){ for(auto i:num){ if(i!=32&&(i<65||i>90)) return false; } return true; } vector<int> find_magic_number(vector<int>nums){ vector<int> res; for(int i=0;i<1000;i++){ auto temp=nums; for(auto & num:temp){ num-=i; } if(is_valid_ascii(temp)) res.push_back(i); } return res; } int main(int argc,char** argv) { int N; cin>>N; vector<int> cipher(N); for(int i=0;i<N;i++){ int cur; cin>>cur; cipher[i]=cur; } auto res=find_magic_number(cipher); if(res.size()!=1) cout<<res.size()<<endl; else{ for(auto& i:cipher){ i-=res[0]; char c=i; cout<<c; } cout<<endl; } return 0; }
第二题 #include <iostream> #include <vector> #include <algorithm> #include <string> #include <unordered_map> #include <stack> using namespace std; unordered_map<char,string> color; bool isColor(char c){ return c=='R'||c=='G'||c=='B'||c=='K'||c=='Y'||c=='W'||c=='P'; } bool judge(string s){ for(auto i:s){ if(!(i>='0'&&i<='9'||i>='A'&&i<='F'))return false; } return true; } int main(int argc,char** argv) { color['R']="FF0000"; color['G']="00C932"; color['B']="0000FF"; color['K']="000000"; color['Y']="FFFF00"; color['W']="FFFFFF"; color['P']="FF88FF"; int M; cin>>M; getchar(); while(M--){ string s; getline(cin,s); vector<pair<string,string>> res; int len(s.size()); stack<string> stk_color; string do_color; for(int i=0;i<len;i++){ if(s[i]=='#'&&i+1<len&&isColor(s[i+1])){ if(!stk_color.empty()&&!do_color.empty()){ res.push_back({do_color,stk_color.top()}); do_color.clear(); } stk_color.push(color[s[i+1]]); i++; }else if(s[i]=='#'&&i+7<len&&s[i+1]=='C'&&judge(s.substr(i+2,6))){ if(!stk_color.empty()&&!do_color.empty()){ res.push_back({do_color,stk_color.top()}); do_color.clear(); } stk_color.push(s.substr(i+2,6)); i+=7; }else if(s[i]=='#'&&i+1<len&&s[i+1]=='n'){ if(stk_color.empty()) continue; res.push_back({do_color,stk_color.top()}); do_color.clear(); stk_color.pop(); i++; }else{ if(!stk_color.empty())do_color.push_back(s[i]); } } if(!stk_color.empty()&&!do_color.empty()){ res.push_back({do_color,stk_color.top()}); do_color.clear(); stk_color.pop(); } if(res.size()==0){ cout<<"empty"<<endl; }else{ for(auto i:res){ cout<<i.first<<" "<<i.second<<endl; } } } return 0; }