P8723 [蓝桥杯 2020 省 AB3] 乘法表
思路:优先先建一个string的数组存储1到36对应字符,然后就要分情况,小于10和大于10的数字
#include <iostream>
#include <string>
using namespace std;
int n;
string s[]={"0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F","G","H","I","J"
,"K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"};
int main()
{
cin>>n;
for(int i=1;i<n;i++)
{
for(int j=1;j<=i;j++)
{
if(i<10){
printf("%d*%d=",i,j);
if(i*j/n!=0) cout<<s[i*j/n];
cout<<s[i*j%n]<<" ";
}
else if(i>=10&&j<10)
{
cout<<s[i];
printf("*%d=",j);
if(i*j/n!=0) cout<<s[i*j/n];
cout<<s[i*j%n]<<" ";
}
else if(i>=10&&j>=10)
{
cout<<s[i]<<"*"<<s[j]<<"=";
if(i*j/n!=0) cout<<s[i*j/n];
cout<<s[i*j%n]<<" ";
}
}
cout<<endl;
}
return 0;
}
P8641 [蓝桥杯 2016 国 C] 赢球票
思路:以每个数为起点遍历列表,遍历结束的条件是所有数字取完或者是出现了比数组里最大数还大的数
#include <iostream>
using namespace std;
int n;
int q1[110];
int main()
{
cin>>n;
int max2=0记录数组最大数,maxs=0;
for(int i=1;i<=n;i++)
{
cin>>q1[i];
max2=max(max2,q1[i]);
}
for(int i=1;i<=n;i++)
{
int f[110]={0},sum=0,j=i,x=1,m=n;
while(1)
{
if(f[j]==0)
{
if(x==q1[j])
{
sum+=q1[j];
f[j]=1;
x=0;
maxs=max(maxs,sum);
m--;
}
x++;
}
if(x>max2||m<=0) break;退出条件
j++;
if(j==n+1) j=1;环形结构,重新遍历
}
}
cout<<maxs;
return 0;
}