题解分享
题解分享简介
九进制转十进制(结果填空) - 题解
```
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
string s;
LL res, base, k = 0;
int main()
{
cin >> s >> base;
for (int i = s.size() - 1; i >= 0; i -- )
{
if(s[i] >= 'A')
//s[i] - 'A': 当s[i]是一个大写字母时,这部分代码会将其转换为对应的十进制数字。
//例如,当s[i]是'A'时,结果为0;当s[i]是'B'时,结果为1,以此类推。
res += (s[i] - 'A' + 10) * pow(base, k++);
//s[i] - '0' 这部分代码用于将字符s[i]从其ASCII码值表示转换为对应的十进制数字。
else
res += (s[i] - '0') * pow(base, k++);
}
cout << res;
return 0;
}
```
查看全文
0
0
0
1
九进制转十进制(结果填空) - 题解
```
public class Main {
public static void main(String[] args) {
// 使用Integer自带函数
// Integer res=Integer.valueOf(String.valueOf(2022), 9);
// 正常做法
int n=2022,res=0,count=0;
while(n>0) {
res+=(n%10)*Math.pow(9, count++);
n/=10;
}
System.out.println(res);
}
}
```
查看全文
0
0
0
1
九进制转十进制(结果填空) - 题解
```
#include<iostream>
#include<cstring>
#include<algorithm>
#include<math.h>
using namespace std;
int main()
{
string s="2022";
int k=1;
int ans=0;
for(int i=3;i>=0;i--)
{
ans+=(s[i]-'0')*k;
k*=9;
}
cout<<ans<<endl;
return 0;
}
```
查看全文
0
0
0
0



