招行卡中心笔试 4.8
第一次编程全AC(虽然就两道)
第一次提前交卷(虽然就提前了五分钟)
第一次提前交卷(虽然就提前了五分钟)
第一题
#include<iostream>
#include<map>
using namespace std;
int main(){
int T;
cin>>T;
map<char,char> table;
table['1']='1';
table['2']='5';
table['3']='8';
table['4']='7';
table['6']='9';
table['5']='2';
table['8']='3';
table['7']='4';
table['9']='6';
cin.ignore();
while(T--){
string s;
getline(cin,s);
bool flag=true;
int left=0,right=s.size()-1;
while(left<=right){
if(table[s[left]]!=s[right]){
flag=false;
break;
}
}
if(flag==true){
cout<<"YES"<<endl;
}else{
cout<<"NO"<<endl;
}
left++;
right--;
}
return 0;
} 第二题,动态规划,一个大问题可分为3个小问题 #include<iostream>
using namespace std;
int allSolution(string &s,int i,int j,long long target){
long long result=0;
for(int m=i;m<=j;m++){
result=result*10+(s[m]-'0');
}
if(i==0){
if(target==result)
return 1;
else
return 0;
}
int count=allSolution(s,i-1,i-1,target-result)+allSolution(s,i-1,i-1,target+result)+allSolution(s,i-1,j,target);
return count;
}
int main(){
int T;
cin>>T;
while(T--){
string s;
int k;
cin>>s;
cin>>k;
cout<<allSolution(s,s.size()-1,s.size()-1,k)<<endl;
}
return 0;
}

