深信服c++笔试
题目1: 魔法棒
题目2:字符串修改
第一题 int 改为 long 可以AC
第二题 自测ok,case通过一直为 0
有没有大佬贴下第二题AC代码~
我先贴上我的,哭了
#include <iostream>
#include <sstream>
using namespace std;
int main() {
long n;
string s;
cin>>s;
cin>>n;
int res[10]={-1,-1,-1,-1,-1,-1,-1,-1,-1,-1};
while(n-->0){
int a,b;
cin>>a>>b;
res[a] = b;
for(int i=0;i<10;i++){
if(res[i]==a){
res[i] = b;
}
}
}
for(long i=0;i<s.size();i++){
int index = s[i] - '0';
if(res[index]!= -1)
s[i] = (res[index]) + '0';
}
cout<< s;
return 0;
} 
查看7道真题和解析