第十届蓝桥杯大赛青少年创意编程Python组省赛

A. 第一题
Description
用 1、3、5、8 这几个数字,能组成的互不相同且无重复数字的三位数各是多少?总共有多少个?

Output
从小到大输出多行数字,每行一个三位数,

组成的三位数的总个数

#include<bits/stdc++.h>
using namespace std;
int main()
{
    cout<<135<<endl;
    cout<<138<<endl;
    cout<<153<<endl;
    cout<<158<<endl;
    cout<<183<<endl;
    cout<<185<<endl;
    cout<<315<<endl;
    cout<<318<<endl;
    cout<<351<<endl;
    cout<<358<<endl;
    cout<<381<<endl;
    cout<<385<<endl;
    cout<<513<<endl;
    cout<<518<<endl;
    cout<<531<<endl;
    cout<<538<<endl;
    cout<<581<<endl;
    cout<<583<<endl;
    cout<<813<<endl;
    cout<<815<<endl;
    cout<<831<<endl;
    cout<<835<<endl;
    cout<<851<<endl;
    cout<<853<<endl;
    cout<<24<<endl;
    return 0;
}

B. 第二题
Description
打印出 1~1000 之间包含 3 的数字;

如果 3 是连在一起的(如 233)则在数字前加上&;

如果这个数字是质数则在数字后加上*,例:(3*,13*,23*,&33,43*…&233*…)。

Output
按照题意从小到大输出数字,每行一个数字;

#include<bits/stdc++.h>
using namespace std;
bool ss(int x);
int main()
{
    int i;
    int a[3];
    for(i=1;i<=1000;i++)
    {
        a[0]=i/100;
        a[1]=(i-a[0]*100)/10;
        a[2]=i%10;
        if(a[0]==3||a[1]==3||a[2]==3)
        {
            if(i>=100&&i<1000)
            {
                if((a[0]==3&&a[1]==3)||(a[1]==3&&a[2]==3))
                {
                    cout<<'&';
                }
            }
            if(i>=10&&i<=99)
            {
                if(a[1]==3&&a[2]==3)
                {
                    cout<<'&';
                }
            }
            cout<<i;
            if(ss(i))
            {
                cout<<'*';
            }
            cout<<endl;
        }
    }
    return 0;
}
bool ss(int x)
{
    int i;
    if(x==2)
    {
        return true;
    }
    if(x<3)
    {
        return false;
    }
    for(i=2;i<=sqrt(x);i++)
    {
        if(x%i==0)
        {
            return false;
        }
    }
    return true;
}

C. 第三题
Description
让用户在一次输入时输入 N 个数字(2<=N<=15,即每次输入的数字数量不同),数字之间以“,”作为分隔。

然后组合显示:

(1)用户输入的数字个数;

(2)用户输入的最小的数字;

(3)将用户输入的数字按从大到小进行排列输出,数字之间以“,”作为分隔;

(4)如果用户输入的数字小于等于 26,则找到相对应的 26 个大写英文字母(1 对应“A”,26 对应“Z”),并拼接在一起打印显示,如果输入的数字在 1~26 之外则不显示相应字母。(例:程序输入 214,则显示输出“[bad]”)。

Input
N 个数字,2<=N<=15

Output
输入的数字个数

输入的最小数字

输入的数字从大到小排列

输入的数字所对应的字母

Sample Input
9,12,15,22,5,21,214
Sample Output
7
5
214,22,21,15,12,9,5
ILOVEU[bad]

#include<bits/stdc++.h>
using namespace std;
string b[16];
int a[16],bb[16];
int gs,gs1;
void fenli(string s);
void zh();
int main()
{
    int i,zx,gs,aa,j;
    string s;
    cin>>s;
    zx=999999999;
    fenli(s);
    zh();
    for(i=1;i<=gs1;i++)
    {
        zx=min(a[i],zx);
    }
    cout<<zx<<endl;
    for(i=1;i<=gs1;i++)
    {
        bb[i]=a[i];
    }
    sort(a+1,a+gs1+1);
    for(i=gs1;i>=2;i--)
    {
        cout<<a[i]<<',';
    }
    cout<<a[1]<<endl;
    for(i=1;i<=gs1;i++)
    {
        if(bb[i]<=26)
        {
            cout<<(char)(bb[i]+64);
        }
        else
        {
            aa=b[i].size();
            cout<<'[';
            cout<<"bad";
            cout<<']';
        }
    }
    return 0;
}
void fenli(string s)
{
    int qs,aa,i,j;
    aa=s.size();
    qs=0;
    for(i=0;i<aa;i++)
    {
        if(s[i]==',')
        {
            gs++;
            for(j=qs;j<i;j++)
            {
                b[gs]=b[gs]+s[j];
            }
            qs=i+1;
        }
    }
    gs++;
    for(j=qs;j<aa;j++)
    {
        b[gs]=b[gs]+s[j];
    }
    cout<<gs<<endl;
    qs=i+1;
    gs1=gs;
}
void zh()
{
    int i,j,t250=1,aa;
    for(i=1;i<=gs;i++)
    {
        aa=b[i].size();
        t250=1;
        for(j=aa-1;j>=0;j--)
        {
            a[i]+=(b[i][j]-'0')*t250;
            t250*=10;
        }
    }
}
  • 3
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值