关于蓝桥杯十六进制转八进制
为什么我的代码就是不过呢。求大神指教
#include <bits/stdc++.h>
#include <map>
using namespace std;
int main()
{
int n;
map<int,int> p;
string M;
M.resize(100000000);
int len,temp;
map<int,int>::iterator pr;
for(int i=0;i<16;i++){
if(i<10){
p.insert(pair<int,int>((i+48),i));
}else{
p.insert(pair<int,int>((i+55),i));
}
}
scanf("%d",&n);
while(n--){
cin>>M;
len=M.length();
int j=0;
for(int i=len-3*(len/3);i<=len;i+=3){
temp=0;
while(j<i){
pr=p.find(M[j]);
temp=temp*16+pr->second;
j++;
}
if(i==0)continue;
int sum[4];
for(int k=0;k<4;k++){
sum[k]=0;
}
int k;
for( k=3;temp!=0;k--){
sum[k]=(temp&7);
temp=temp>>3;
}
if(i<=3){
temp=0;
for(int t=0;t<4;t++){
temp=temp*10+sum[t];
}
cout<<temp;
}else{
for(k=(k==0?k:k+1);k<=3;k++)
cout<<sum[k];
}
}
cout<<endl;
}
return 0;
}