[蓝桥杯 2020 省 AB3] 乘法表
进制转换
题目描述
九九乘法表是学习乘法时必须要掌握的。在不同进制数下,需要不同的乘法表。
例如, 四进制下的乘法表如下所示:
1*1=1
2*1=2 2*2=10
3*1=3 3*2=12 3*3=21
请注意,乘法表中两个数相乘的顺序必须为样例中所示的顺序,不能随意交换两个乘数。
给定 P P P,请输出 P P P 进制下的乘法表。
输入格式
输入一个整数 P P P。
输出格式
输出
P
P
P 进制下的乘法表。
P
P
P 进制中大于等于
10
10
10 的数字用大写字母 A
、B
、C
、
⋯
\cdots
⋯ 表示。
样例 #1
样例输入 #1
4
样例输出 #1
1*1=1
2*1=2 2*2=10
3*1=3 3*2=12 3*3=21
样例 #2
样例输入 #2
8
样例输出 #2
1*1=1
2*1=2 2*2=4
3*1=3 3*2=6 3*3=11
4*1=4 4*2=10 4*3=14 4*4=20
5*1=5 5*2=12 5*3=17 5*4=24 5*5=31
6*1=6 6*2=14 6*3=22 6*4=30 6*5=36 6*6=44
7*1=7 7*2=16 7*3=25 7*4=34 7*5=43 7*6=52 7*7=61
提示
对于所有评测数据, 2 ≤ P ≤ 36 2 \leq P \leq 36 2≤P≤36。
蓝桥杯 2020 第三轮省赛 AB 组 G 题。
#include<bits/stdc++.h>
using namespace std;
int jz;
string zm="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string trans(int x){
string ans{};
if(x/jz>=10)ans+=zm[x/jz-10];
else if(x/jz>0)ans+=to_string(x/jz);
if(x%jz>=10)ans+=zm[x%jz-10];
else ans+=to_string(x%jz);
return ans;
}
int main(){
ios::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);
cin>>jz;
for(int i=1;i<jz;++i){
for(int j=1;j<=i;++j)cout<<trans(i)<<"*"<<trans(j)<<"="<<trans(i*j)<<" ";
cout<<endl;
}
return 0;
}
/*
#include<bits/stdc++.h>
using namespace std;
int n;
char trans(int a){
if(a%n<10) return a%n+'0';
return a%n-10+'A';//大于10时用大写字母
}
string ten_to_k(int x){//10进制转k进制
string ans;//字符串存储
while(x>0)ans+=trans(x),x/=n;//短除法
reverse(ans.begin(),ans.end());//翻转字符串,因为是从下往上
return ans;
}
int main(){
cin>>n;
for(int i=1;i<n;i++,putchar(10))//pc10用来换行
for(int j=1;j<=i;j++)
cout<<ten_to_k(i)<<"*"<<ten_to_k(j)<<"="<<ten_to_k(i*j)<<" ";//循环输出
return 0;
}
*/