题目连接:http://www.ifrog.cc/acm/problem/1056
DESCRIPTION
Two octal number integers a, b are given, and you need calculate the result a - b in octal notation.
If the result is negative, you should use the negative sign instead of complement notation.
INPUT
The first line is an integer T(1 <= T <= 1000), indicating the number of test cases.
For each case, the first and only line contains two octal integers a, b.
(0 <= a, b < 2^32)
OUTPUT
Print the result, one per line, in octal notation.
SAMPLE INPUT
1
76 7
SAMPLE OUTPUT
67
你看这个题很正常。。是个水题吧。。
但是我在做这个题的时候经历很曲折,在此记录一下自己zz的一些细节和错误,供以后警醒
一上来,我看到了2^32,查了英文单词oct是八进制,然后我觉得可以先换成十进制,然后相减,
然后换的时候预处理每一位的权重的时候。。base[i]=8*base[i-1]这个不是用来做输入的八进制转换到10进制的转换么
我居然又把残留印象的32当成了输入的8进制数的位数,然后算了一下是2的96次方。。long long也存不下啊
然后我就想到了大数去解。。这tm还带在做的过程中忘记以前的题意私自篡改题意的。。Orz,所以我们在遇到
一个困难的事。。要仔细地阅读一遍题,虽然很难受。。但是你要咬牙把这个题看完,因为这是校验信息的一部分,
这是你做题的前提
嗯,然后我没有做这件事情。。继续往下面搞了
#include <iostream> #include <cstdio> #include <vector> #include <algorithm> #include <cstring> using namespace std; typedef long long ll; char x[10000],y[10000],c[10000]; int T; vector<int> ans; int jud(char *x,char *y){ int len_x=strlen(x); int len_y=strlen(y); if(len_x<len_y) return true; else if(len_x==len_y){ int i; for(i=0;i<len_x;++i){ if(y[i]>x[i]) return true; } } return false; } void Minus(){ int len_x=strlen(x); int len_y=strlen(y); int move=len_x-len_y; int i; //对齐 for(i=len_x-1;i>=len_x-len_y&&move;--i){ y[i]=y[i-move]; y[i-move]='0';//补零 } // printf("y:%s x:%s ",y,x); // printf("lenx:%d ",strlen(x)); // printf("leny:%d ",strlen(y)); int cnt=0; for(i=len_x-1;i>=0;--i){ cnt++; if((x[i]-'0')<(y[i]-'0')&&cnt<=len_y){ x[i-1]-=1;//error i+1->i-1 x[i]+=8; x[i]-=y[i]-'0'; } else if(cnt<=len_y){ x[i]-=y[i]-'0'; } } for(i=len_x-1;i>=0;--i){ if(x[i]-'0'<0){ x[i-1]-=1; x[i]+=8; } ans.push_back(x[i]-'0'); } // for(i=ans.size()-1;i>=0;--i){ // printf("%d",ans[i]); // } // printf(" "); // printf("lenx:%d ",strlen(x)); } void shortx(){ int len=strlen(x); for(int i=0;i<len-1;++i){ x[i]=x[i+1]; } x[len-1]='