ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#206810 | #3719. 加密通话 | wyz_ | 100 | 90ms | 1692kb | C++11 | 3.2kb | 2024-07-25 18:28:55 | 2024-07-25 20:22:03 |
answer
#include<bits/stdc++.h>
using namespace std;
#define _BIGINT_MAXN_H_ 100000
struct BigInt{
char num[_BIGINT_MAXN_H_];
int len;
bool neg;
BigInt(){
memset(num,0,sizeof num);
len = 0, neg = 0;
}
}ans,n26;
string s;
string wd = " abcdefghijklmnopqrstuvwxyz";
void read(BigInt&);
void write(const BigInt&);
void del0(BigInt&);
BigInt abs(const BigInt&);
BigInt toBigInt(int);
bool operator < (const BigInt&,const BigInt&);
BigInt operator + (const BigInt&,const BigInt&);
BigInt operator - (const BigInt&,const BigInt&);
BigInt operator - (const BigInt&);
BigInt operator * (const BigInt&,const BigInt&);
int main(){
cin >> s;
ans.len = 1;
n26 = toBigInt(26);
for(int i = 0; i < int(s.size()); i++){
ans = ans * n26;
ans = ans + toBigInt(wd.find(s[i]));
}
write(ans);
return 0;
}
void read(BigInt& n){
while(n.num[0] = getchar(), !isdigit(n.num[0]) && n.num[0] != '-'){};
if(n.num[0] == '-')
n.neg = 1, n.num[0] = getchar();
while(isdigit(n.num[n.len])){
n.num[n.len] ^= 48;
n.num[++n.len] = getchar();
}
n.num[n.len] = 0;
reverse(n.num, n.num + n.len);
}
void write(const BigInt& n){
if(n.len <= 1 && !n.num[0]){
printf("0\n");
return;
}
if(n.neg)
putchar('-');
for(int i = n.len-1; i >= 0; i--)
putchar(n.num[i] | 48);
putchar('\n');
}
void del0(BigInt& n){
while(n.len > 1 && !n.num[n.len-1])
n.len--;
}
BigInt abs(const BigInt& n){
BigInt x = n;
x.neg = 0;
return x;
}
BigInt toBigInt(int n){
BigInt x;
while(n){
x.num[x.len++] = n % 10;
n /= 10;
}
return x;
}
bool operator < (const BigInt& a,const BigInt& b){
if(a.neg != b.neg)
return a.neg;
if(a.neg){
if(a.len != b.len)
return a.len < b.len;
for(int i = a.len-1; i >= 0; i--){
if(a.num[i] != b.num[i])
return a.num[i] > b.num[i];
}
}
else{
if(a.len != b.len)
return a.len < b.len;
for(int i = a.len-1; i >= 0; i--){
if(a.num[i] != b.num[i])
return a.num[i] < b.num[i];
}
}
return 0;
}
BigInt operator + (const BigInt& a,const BigInt& b){
if(a.neg != b.neg){
if(a.neg){
BigInt tmp = a;
tmp.neg = 0;
return b - tmp;
}
else{
BigInt tmp = b;
tmp.neg = 0;
return a - tmp;
}
}
BigInt c;
c.len = max(a.len,b.len), c.neg = a.neg;
int m = 0;
for(int i = 0; i < c.len; i++){
m += a.num[i] + b.num[i];
c.num[i] = m % 10;
m /= 10;
}
if(m)
c.num[c.len++] = m;
return c;
}
BigInt operator - (const BigInt& a){
BigInt x = a;
x.neg = !x.neg;
return x;
}
BigInt operator - (const BigInt& a,const BigInt& b){
BigInt c;
if(b.neg){
BigInt tmp = b;
tmp.neg = 0;
return a + tmp;
}
if(a < b){
c = b - a;
c.neg = 1;
return c;
}
bool brw = 0;
c.len = max(a.len,b.len);
for(int i = 0; i < c.len; i++){
c.num[i] = a.num[i] - b.num[i] - brw;
if(c.num[i] < 0)
c.num[i] += 10, brw = 1;
else
brw = 0;
}
del0(c);
return c;
}
BigInt operator * (const BigInt& a,const BigInt& b){
BigInt c;
c.len = a.len + b.len, c.neg = a.neg ^ b.neg;
for(int i = 0; i < a.len; i++){
for(int j = 0; j < b.len; j++){
c.num[i+j] += a.num[i] * b.num[j];
c.num[i+j+1] += c.num[i+j] / 10;
c.num[i+j] %= 10;
}
}
del0(c);
return c;
}
Details
小提示:点击横条可展开更详细的信息
Test #1:
score: 10
Accepted
time: 0ms
memory: 1680kb
input:
aaa
output:
703
result:
ok single line: '703'
Test #2:
score: 10
Accepted
time: 0ms
memory: 1684kb
input:
otto
output:
277695
result:
ok single line: '277695'
Test #3:
score: 10
Accepted
time: 0ms
memory: 1684kb
input:
wonder
output:
280375204
result:
ok single line: '280375204'
Test #4:
score: 10
Accepted
time: 1ms
memory: 1680kb
input:
abitwzdkxul
output:
154073598812678
result:
ok single line: '154073598812678'
Test #5:
score: 10
Accepted
time: 0ms
memory: 1680kb
input:
opgwlppmlumy
output:
57356751904151439
result:
ok single line: '57356751904151439'
Test #6:
score: 10
Accepted
time: 0ms
memory: 1684kb
input:
jwwvqldtsjskf
output:
1042077430022487696
result:
ok single line: '1042077430022487696'
Test #7:
score: 10
Accepted
time: 19ms
memory: 1688kb
input:
jfrioyvbyqsoxygmajdiqorgijlhkhbwwjawtwckokqyvxrdsqymffhfbuwajpuoqbcnddsyevhkapeusipgjvszubapviqtvmrz...
output:
4300911453790411800945391903152765942782793138336118343042260142874506488263785673172087778384488963...
result:
ok single line: '430091145379041180094539190315...9276413044766128134123598377397'
Test #8:
score: 10
Accepted
time: 22ms
memory: 1684kb
input:
udbsljdblcgcdylvoettkrrxsonxxwzpwcxtjnqbvbirbsrgliszqfqkaiwydmmxknyaryrfjogtianswvlqzsmyscvsiipecngs...
output:
1487898281503557831748070024669444336196763093279730130921507188777488934832629510294231582511917662...
result:
ok single line: '148789828150355783174807002466...3974947859267251785532872755112'
Test #9:
score: 10
Accepted
time: 24ms
memory: 1692kb
input:
gursgiqzlcfqnjjxjowqzubnydiygjxestvlehffjkybkmnrsbzzkprrnyvmppxwwyhmjmsfukcpjmmltovusjaqzfmhdsqjkcsx...
output:
6050651831854106655593124171348136351661687936535471990086285246928592125170210941171129207820422193...
result:
ok single line: '605065183185410665559312417134...0496840954331952742930298239413'
Test #10:
score: 10
Accepted
time: 24ms
memory: 1688kb
input:
vgkblomiykrhfzqnuwhrnmrjbqpflvpqlpivadvtwilhsbpttuolnfztlmcoctewhjrsjmhlgnlbginckuabmaogphxqkiweuubw...
output:
7504794918572298229797229224430944880316394524818964978603096666297543234087454896646797196502491357...
result:
ok single line: '750479491857229822979722922443...1605770094120254709299186651392'