#10659: 瘋狂RE 有人可以提供RE可能嗎


310573sao (Jiburiru)

學校 : 新北市立板橋高級中學
編號 : 48055
來源 : [59.127.176.2]
最後登入時間 :
2020-04-01 20:44:03
c132. 00619 - Numerically Speaking -- UVa619 | From: [220.135.171.68] | 發表日期 : 2016-01-26 21:09

int p[100] = {};
int mn(){ //makenum
int a[100] = {};
for (int i = 0; i < 100; i++)
a[i] = p[i];
int j = 99;
while (!a[j])j--;
for (;j > 0; j--){
a[j - 1] += a[j] * 10;
a[j] = 0;
a[j - 1] %= 26;
}
a[0] %= 26;
if (a[0] % 26 == 0)
return 26;
return a[j];
}
void divide(){
int j = 99;
while (!p[j])j--;
for(; j > 0; j--){
p[j - 1] += p[j] % 26 * 10;
p[j] /= 26;
}
p[0] /= 26;
return;
}
int main(){
string s;
while (cin >> s, s != "*"){


if (isdigit(s[0])){
/*string t = "";
int i = 0;
while (s[i] == '0')i++;
for (int j = i; j < s.size(); j++)
t += s[j];
s = t;*/

int len = s.size() - 1;
for (int i = len; i >= 0; i--) // arr 012
p[i] = s[len - i] - '0'; // 123 -> 321
int top = len;
int a = 0;
string ans = "";
int num = 1;
while (num){
a = mn();
ans += char(a + 96);
p[0] -= a;
divide();
num = 0;
for (int i = 0; i < 99; i++)
if (p[i]>0){ num = 1; break; }
}
for (int i = ans.size() - 1; i >= 0; i--)
cout << ans[i];
for (int i = 0; i < 22 - ans.size(); i++)
cout << ' ';
len++;
for (int i = 0; i < len%3; i++)
cout << s[i];
if (len>3)
cout << ',';
for (int i = len%3, c = 0; i < s.size(); i++, c++){
cout << s[i];
if (c % 3 == 2&&c&&i!=s.size()-1)cout << ',';
}
cout << endl;
}
else{ //en->num
cout << s;
for (int i = 0; i < 22 - s.size(); i++)
cout << ' ';
int p[100] = {};
for (int i = 0; i < s.size(); i++){
int a = s[i] - 'a' + 1;
p[0] += a;
if (i != s.size() - 1){
int b= 99;
while (!p[b])b--;
for (int i = b; i >= 0; i--)
p[i] *= 26;
}
for (int i = 0; i < 99; i++){
p[i + 1] += p[i] / 10;
p[i] %= 10;
}
}
int k = 99;
while (!p[k])k--;
k++;
for (int i = 0; i < k % 3; i++){
cout << p[k - i - 1];
}

if (k%3&&k>3)
cout << ',';
k -= k % 3;
for (int i = k-1, c = 0; i>=0; i--, c++){
cout << p[i];
if (c % 3 == 2 && c&&i)cout << ',';
}
cout << endl;
}
}
}

 
ZeroJudge Forum