入门赛 E 题。
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double register int
#define ri register int
const int N = 1e5 + 5;
int n, a[N];
inline int change(int x){
for(int i = 1; i <= a[x]; i++){
int sum = 0;
while(x){
sum += x % 10;
x /= 10;
}
x = sum;
if(x <= 9) break;
}
return x;
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n;
for(int i = 1; i <= n; i++) cin >> a[i];
for(int i = 1; i <= n; i++) cout << change(i) << ' ';
return 0;
}
就 WA 了。
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double register int
#define ri register int
const int N = 1e5 + 5;
int n, a[N];
signed main(){
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n;
for(int i = 1; i <= n; i++) cin >> a[i];
for(int i = 1; i <= n; i++){
int x = i;
for(int j = 1; j <= a[i]; j++){
int sum = 0;
while(x){
sum += x % 10;
x /= 10;
}
x = sum;
if(x <= 9) break;
}
cout << x << ' ';
}
return 0;
}
就对了。