原题
P1898 缘分计算
AC代码
C++#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N = 10010;
string s;
int st,idx;
int a[N],b[N];
int change(char c){
return (int)(c - 'A' + st);
}
int f(int x){
int cnt = 0;
while(x) x /= 10,cnt ++;
return cnt;
}
bool stop_check(){
if(idx > 3) return 1;
if(idx == 3 && a[1] == 1 && a[2] == 0 && a[3] == 0) return 0;
if(idx == 2) return 0;
return 1;
}
signed main(){
cin >> s >> st;
for(int i = 0 ; i < s.length() ; i ++){
int tt = change(s[i]),len = f(tt);
idx += len;
for(int j = 0; j < len; j++) {
a[idx - j] = tt % 10;
tt /= 10;
}
}
while(stop_check()){
for(int i = 1 ; i < idx ; i ++)
b[i] = (a[i] + a[i + 1]) % 10;
for(int i = 1 ; i < idx ; i ++)
a[i] = b[i];
idx --;
}
if(idx == 3) return cout << 100,0;
if(a[1] == 0) return cout << a[2],0;
cout << a[1] << a[2];
return 0;
}
ST生成器
C++#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N = 10010;
string s;
int idx;
int a[N],b[N];
int change(char c,int st){
return (int)(c - 'A' + st);
}
int f(int x){
int cnt = 0;
while(x) x /= 10,cnt ++;
return cnt;
}
bool stop_check(){
if(idx > 3) return 1;
if(idx == 3 && a[1] == 1 && a[2] == 0 && a[3] == 0) return 0;
if(idx == 2) return 0;
return 1;
}
signed main(){
cin >> s;
for(int st = 1 ; st <= 10000 ; st ++){
idx = 0;
for(int i = 0 ; i < s.length() ; i ++){
int tt = change(s[i],st),len = f(tt);
idx += len;
for(int j = 0; j < len; j++) {
a[idx - j] = tt % 10;
tt /= 10;
}
}
while(stop_check()){
for(int i = 1 ; i < idx ; i ++)
b[i] = (a[i] + a[i + 1]) % 10;
for(int i = 1 ; i < idx ; i ++)
a[i] = b[i];
idx --;
}
if(idx == 3 && a[1] == 1 && a[2] == 0 && a[3] == 0) cout << st << '\n';
}
return 0;
}