| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
什么破数据,zzzzzzzzz对应的数字该显示zzzzzz显示aaaaaaa也能过?????正确的显示还给WA了!!!这破题数据绝对有问题。
下面代码能过,但连最后一个数据输入数字显示zzzzzzzz都不行。可以试试26、676等全是错。
然而写的所有数据都能通过的还给WA了。。。什么情况??
不信自己试试!!!
#include <iostream>
#include <sstream>
using namespace std;
const int size = 50;
struct hp{
int len, s[size+1];
};
void hp_cpy(hp &a, const hp &b){
a.len = b.len;
for(int i=1; i<=a.len; i++)
a.s[i] = b.s[i];
}
void hp_new(hp &a, string str){
int i;
while(str[0]=='0' && str.size()!=1)
str.erase(0, 1);
a.len = (int)str.size();
for(i=1; i<=a.len; ++i)
a.s[i] = str[a.len-i] - '0';
for (i=a.len+1; i<=size; ++i)
a.s[i] = 0;
}
void hp_show(const hp &y){
int i;
int n = y.len%3;
for(i=y.len; i>=1; i--){
cout << y.s[i];
if((y.len-i-n+1)%3 == 0 && i!=1) cout << ',';
}
cout << endl;
}
void divide(const hp &a, int b, hp &c, int &d){
int i,len;
for(i=1; i<=size; i++)
c.s[i] = 0;
len = a.len;
d = 0;
for(i=len; i>=1; i--){
d = d*10 + a.s[i];
c.s[i] = d/b;
d %= b;
}
while(len>1 && c.s[len]==0) len--;
c.len=len;
}
void multiply(const hp &a, int b, hp &c){
int i, len;
for(i=1; i<=size; i++)
c.s[i] = 0;
len = a.len;
for(i=1; i<=len; i++){
c.s[i] += a.s[i]*b;
c.s[i+1] += c.s[i]/10;
c.s[i] %= 10;
}
len++;
while(c.s[len] >= 10){
c.s[len+1] += c.s[len]/10;
c.s[len] %= 10;
len++;
}
while(len>1 && c.s[len]==0)
len--;
c.len = len;
}
void addition(const hp &a, const hp &b, hp &c){
int i, len;
for(i=1; i<=size; i++)
c.s[i] = 0;
if(a.len > b.len) len = a.len;
else len = b.len;
for(i=1; i<=len; i++){
c.s[i] += a.s[i]+b.s[i];
if(c.s[i] >= 10){
c.s[i] %= 10;
c.s[i+1]++;
}
}
if(c.s[len+1] > 0) len++;
c.len = len;
}
int main(){
stringstream s;
string str, tmp3;
int i, j, len, p, r;
hp tmp1, tmp2, dec, q;
while(cin >> str && str != "*"){
if(str[0] >= '0' && str[0] <= '9'){
p = 0;
hp_new(dec, str);
while(!(dec.len == 1 && dec.s[1] == 0)){
divide(dec, 26, q, r);
hp_cpy(dec, q);
tmp1.s[p++] = r;
}
for(i=p-1; i>=0; i--)
cout << char(tmp1.s[i] + 'a' - 1);
for(i=0; i<22-p; i++)
cout << ' ';
len = str.length();
r = len%3;
for(i=0; i<len; i++){
cout << str[i];
if((i-r+1)%3 == 0 && i!=len-1) cout << ',';
}
cout << endl;
}
else{
len = str.length();
cout << str;
for(i=0; i<22-len; i++)
cout << ' ';
hp_new(dec, "0");
for(i=len-1; i>=0; i--){
s.clear();
s << (str[i] - 'a' + 1);
s >> tmp3;
hp_new(tmp2, tmp3);
for(j=0; j<len-i-1; j++){
multiply(tmp2, 26, tmp1);
hp_cpy(tmp2, tmp1);
}
addition(dec, tmp2, tmp1);
hp_cpy(dec, tmp1);
}
hp_show(dec);
}
}
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator