蓝桥杯训练第一次作业

这是一个关于蓝桥杯训练的博客,涵盖了多种基础的算术操作题目,包括加法、多个数求和、字符统计、进制转换等。题目涉及输入输出的处理,以及对大量数据的计算和判断。通过对这些基础题目的解决,旨在提升编程基本功和问题解决能力。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题目来自于http://oj.acmclub.cn/
当然其中包括来自其他各大OJ平台的题目
直接开始咯

第一次题目比较基础
然而J题还是没有自己做出来
那么就把它拿出来单独写吧


1001A

题目描述
输入两个数A,B,输出A+B的值。

输入
输入多组数据:每组由两个整数(a和b)构成,a和b之间用空格隔开,每组数据单独占一行。
因为不知道有多少组数据,请想办法判断输入何时结束。

输出
每组的两个整数(a和b)求和并输出,每组的求和结果独占一行

样例输入
1 2
12 24
400 500

样例输出
3
36
900

#include <iostream>
using namespace std;
int main()
{
    int A,B;
    while(cin>>A>>B)
    {
        cout<<A+B<<endl;
    }
    return 0;
}

http://paste.ubuntu.com/23845796/


1002B

题目描述
输入两个数A,B,输出A+B的值。

输入
第一行是数据的组数N,从第二行开始是N组由两个整数(a和b)构成的数据,a和b之间用空格隔开,每组输入单独占一行

输出
每组的两个整数(a和b)求和并输出,每组的求和结果独占一行

样例输入
2
1 2
10 20

样例输出
3
30

#include <iostream>
using namespace std;
int main()
{
    int N,A,B;
    cin>>N;
    for(int i=1;i<=N;i++)
    {
        while(cin>>A>>B)
        {
            cout<<A+B<<endl;
        }
    }
    return 0;
}

http://paste.ubuntu.com/23845832/


1003C

题目描述
输入两个数A,B,输出A+B的值。

输入
多组数据:每组由两个整数(a和b)构成,a和b之间用空格隔开,每组输入单独占一行。
当输入为 0 0 时,输入结束。0 0这组数据不处理。

输出
对于每一组测试用例,输出齐对应的和,每组数据一行。

样例输入
1 2
3 4
10 20
0 0

样例输出
3
7
30

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b;
    while(cin>>a>>b)
    {
        if(a==0&&b==0)
    {
        exit(0);
    }
    else
    {
        cout<<a+b<<endl;
    }
    }
    return 0;
}

http://paste.ubuntu.com/23845837/


1004D

题目描述
多个数求和。

输入
输入包含多个测试用例。每个测试用例包含一个正整数N,随后是N个整数跟在同一行上。当某个测试用例以0开始,终止输入,且该用例不处理。

输出
对于每一组测试用例,输出齐对应的和,每组数据一行。

样例输入
3 1 2 4
1 23
5 1 3 5 7 9
0

样例输出
7
23
25

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int N,a[100],sum;
	while(cin>>N)
	{
	    if(N==0)
    {
        exit(0);
    }
    else
    {
        {
            sum=0;
            for(int j=1;j<=N;j++)
            {
                cin>>a[j];
                sum=sum+a[j];
            }
            cout<<sum<<endl;
            }
    }
	}
	return 0;
}

http://paste.ubuntu.com/23845857/


1005E

题目描述
多个数求和。

输入
第一行为N,下面紧跟N行数据。每行数据:开头为M,后面紧跟M个数。

输出
输出每一行M个整数的和,每个数据一行。

样例输入
2
1 1
2 3 4

样例输出
1
7

#include<iostream>
using namespace std;
int main()
{
	int N,M,a[100],sum;
	cin>>N;
	for(int i=1;i<=N;i++)
    {
        cin>>M;
        sum=0;
        for(int j=1;j<=M;j++)
        {
            cin>>a[j];
            sum=sum+a[j];
        }
        cout<<sum<<endl;
    }
	return 0;
}

http://paste.ubuntu.com/23845860/


1009F

题目描述
输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数。

输入

输出

样例输入
a 1,

样例输出
1
1
1
1

#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
    int a=0,b=0,c=0,d=0;
    char ch;
    while((ch=getchar())!='\n')
    {
        if((ch<='z')&&(ch>='a')||(ch<='Z')&&(ch>='A'))
        {
            a++;
        }
        else if(ch==' ')
        {
            b++;
        }
        else if((ch<='9')&&(ch>='0'))
        {
            c++;
        }
        else   d++;
    }
    cout<<a<<endl<<b<<endl<<c<<endl<<d;
    return 0;
}

http://paste.ubuntu.com/23845862/


1011G

题目描述
编程,输入一个10进制正整数,然后输出它所对应的八进制数。

输入

输出

样例输入
10

样例输出
12

#include <stdio.h>
int main()
{
 int num;
 scanf("%d",&num);
 printf("%o",num);
 return 0;
}

http://paste.ubuntu.com/23845870/


1018H

题目描述
谷学长有一个非常简单的问题给你,给你两个整数A和B,你的任务是计算A+B。

输入
输入的第一行包含一个整数T(T<=20)表示测试实例的个数,然后2*T行,分别表示A和B两个正整数。注意整数非常大,那意味着你不能用32位整数来处理。你可以确定的是整数的长度不超过1000。

输出
对于每一个样例,你应该输出两行,第一行是"Case #:",#表示第几个样例,第二行是一个等式"A+B=Sum",Sum表示A+B的结果。注意等式中有空格。

样例输入
2
1
2
112233445566778899
998877665544332211

样例输出
Case 1:
1 + 2 = 3
Case 2:
112233445566778899 + 998877665544332211 = 1111111111111111110

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int main()
{
	char a[1050];
	char b[1050];
	int c[1050];
	int d[1050];
	int e[1050];
	int n,p;
	cin>>n;
	for(p=1;p<=n;p++)
	{
	cin>>a;
	cin>>b;
	int m=0,l=0;
	memset(c,0,sizeof(c));
	memset(d,0,sizeof(d));
	memset(e,0,sizeof(e));
    for(int i=0;i<strlen(a);i++)
    {
        d[i]=a[strlen(a)-1-i]-48;
    }
    for(int i=0;i<strlen(b);i++)
    {
        e[i]=b[strlen(b)-1-i]-48;
    }
        while(l<=strlen(a)||l<=strlen(b))
        {
            c[l]=d[l]+e[l]+m;
            m=c[l]/10;
            c[l]=c[l]%10;

            l++;
        }
        if(m!=0) c[l]=m;
        else
        {
        	l--;
			if(c[l]==0) l=l-1;
		}
		cout<<"Case "<<p<<":"<<endl;
		cout<<a<<" + "<<b<<" = ";
		for(int j=l;j>=0;j--)
		{
		    cout<<c[j];
		}
		cout<<endl;
	}
	return 0;
 }

http://paste.ubuntu.com/23845882/


1019I

题目描述
最近谷学长遇到了麻烦的问题,你能帮帮他吗?
题目是这样的:计算SUM(n) = 1 + 2 + 3 + … + 10^n。满足n<=100 000。

输入
输入包含多组数据,每组数据一行,包括一个整数n(n<=100 000)。当n=-1时输入终止。

输出
对于每个n输出相应的和。

样例输入
1
2
-1

样例输出
55
5050

提示
人家……人家真的不是求和题啦 喵~

#include<iostream>
using namespace std;
int main()
{
	int n;
	while(cin>>n)
	{
		if(n>1)
		{
			for(int i=1;i<=2;i++)
			{
				cout<<"5";
				for(int j=1;j<=(n-1);j++)
				{
					cout<<"0";
				}
			}
		}
		else if(n==0)
		{
			cout<<"1";
		}
		else if(n==1)
		{
			cout<<"55";
		}
		else
		{
			break;
		}
		cout<<endl;
	}
	return 0;
}

http://paste.ubuntu.com/23845891/


1025J


1028K

题目描述
输入一个正整数,输出它的所有质数的因子(如180的质数因子为2、2、3、3、5)

输入

输出

样例输入
180

样例输出
2 2 3 3 5

#include <iostream>
#include <cstring>
using namespace std;
int main()
{
    long int num;
    cin>>num;
    int n=2;
    while(num!=1)
    {
        if(num%n==0)
        {
            cout<<n<<' ';
            num=num/n;
        }
        else
        {
            n++;
        }
    }
    cout<<endl;
    return 0;
}

http://paste.ubuntu.com/23845901/


1029L

题目描述
已知三位整数x和y满足x+y=1333,其中x的个位数是y的百位数,y的个位数是x的百位数,它们的十位数一样。求满足这样条件的x和y。

输入

输出
419+914=1333

按X从小到大输出,每个等式一行

样例输入

样例输出

#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
    int x,y,a,b,c;
    for(b=1;b<=9;b++)
    {
        for(a=3;a<=9;a++)//有题目条件可判断出3+9是最小的
        {
            for(c=9;c>=3;c--)
            {
                x=(100*a)+(10*b)+c;
                y=(100*c)+(10*b)+a;
                if((x+y)==1333)
                {
                    printf("%d+%d=1333\n",x,y);
                }
            }
        }
    }
    return 0;
}

http://paste.ubuntu.com/23845916/


1030M

题目描述
编写一个程序,打印输出半径为1到10的圆的面积,若面积在40到90之间则予以打印,否则,不予打印。

输入

输出
r=? area=??.??

保留两位小数

样例输入

样例输出

#include <iostream>
#include <iomanip>
#define PI 3.1415926
using namespace std;
int main()
{
    float S;
    for(int i=1;i<=10;i++)
    {
        S=PI*i*i;
        if((S>=40)&&(S<=90))
        {
            cout<<"r="<<i<<" area="
            <<fixed<<setprecision(2)<<S<<endl;
        }
    }
    return 0;
}

http://paste.ubuntu.com/23845931/


1031N

题目描述用
选择法对10个整数排序。

输入

输出

样例输入
9 8 7 6 5 4 3 2 1 0

样例输出
0
1
2
3
4
5
6
7
8
9

#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;
int main()
{
    int a[10];
    for(int i=0;i<10;i++)
    {
        cin>>a[i];
    }
    sort(a,a+10);
    for(int k=0;k<10;k++)
    {
        cout<<a[k]<<endl;
    }
    return 0;
}

http://paste.ubuntu.com/23845941/


1032O

题目描述
输入20个整数,输出其中能被数组中其它元素整除的那些数组元素。

输入

输出

样例输入
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21

样例输出
4
6
8
9
10
12
14
15
16
18
20
21

#include<iostream>
using namespace std;
int main()
{
    int a[20];
    for(int i=0;i<20;i++)
    {
        cin>>a[i];
    }
    for(int i=0;i<20;i++)
    {
         for(int j=0;j<20;j++)
         {
             if((a[i]%a[j]==0)&&(i!=j))
             {
                 cout<<a[i]<<endl;
                 break;
             }
         }
    }
    return 0;
}

http://paste.ubuntu.com/23845945/


1040P

题目描述
有三个整数a b c,由键盘输入,输出其中的最大的数。

输入
一行数组,分别为a b c

输出
a b c其中最大的数

样例输入
10 20 30

样例输出
30

#include <iostream>
using namespace std;
int main()
{
    int a,b,c,temp;
    cin>>a>>b>>c;
    a>b?temp=a:temp=b;
    temp>c?cout<<temp:cout<<c;
    return 0;
}

http://paste.ubuntu.com/23845953/


1042Q

题目描述
给出一百分制成绩,要求输出成绩等级‘A’、‘B’、‘C’、‘D’、‘E’。 90分以上为A 80-89分为B 70-79分为C 60-69分为D 60分以下为E

输入
一个整数0-100以内

输出
一个字符,表示成绩等级

样例输入
90

样例输出
A

#include<iostream>
using namespace std;
int main()
{
    int n,k;
    cin>>n;

    if(n>=90)  k=1;
    else if((n>=80)&&(n<=89))  k=2;
    else if((n>=70)&&(n<=79))  k=3;
    else if((n>=60)&&(n<=69))  k=4;
    else   k=5;

    switch(k)
    {
        case 1:cout<<"A"<<endl;break;
        case 2:cout<<"B"<<endl;;break;
        case 3:cout<<"C"<<endl;;break;
        case 4:cout<<"D"<<endl;;break;
        case 5:cout<<"E"<<endl;;break;
    }

    return 0;
}

http://paste.ubuntu.com/23845956/


1047R

题目描述
求Sn=a+aa+aaa+…+aa…aaa(有n个a)之值,其中a是一个数字,本题中,假设a=2。
例如:2+22+222+2222+22222(n=5),n由键盘输入。

输入
n

输出
和Sn

样例输入
5

样例输出
24690

#include <iostream>
using namespace std;
int main()
{
    int n,num=1,sum=0;
    cin>>n;
    for(int i=0;i<n;i++)
    {
    	if(i==0)
    	{
    		num=2;
    		sum+=num;
		}
		else
		{
			num=num*10+2;
			sum+=num;
		}
	}
	cout<<sum<<endl;
    return 0;
}

http://paste.ubuntu.com/23845959/

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值