牛客编程语言练习赛第一场(C++解题)

A.ASCII码

题目描述

BoBo教KiKi字符常量或字符变量表示的字符在内存中以ASCII码形式存储。BoBo出了一个问题给KiKi,转换以下ASCII码为对应字符并输出他们。

73, 32, 99, 97, 110, 32, 100, 111, 32, 105, 116 , 33

输入描述:

输出描述:

转换输出题目中给出的所有ASCII到对应的字符。


AC代码
#include <iostream>
#include <cstdio>
using namespace std;

int main()
{
	printf("%c%c%c%c%c%c%c%c%c%c%c%c",73,32,99,97,110,32,100,111,32,105,116,33);
	return 0;
}

 



B.你能活多少秒

题目描述

 问题:一年约有3.156×107s,要求输入您的年龄,显示该年龄合多少秒。

 

输入描述:

一行,包括一个整数age(0<age<=200)。

输出描述:

一行,包含一个整数,输出年龄对应的秒数。

示例1

输入

20

 

输出

631200000

 

 

 AC代码

#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <stdlib.h>
#include <algorithm>
using namespace std;

int main()
{
	int age;
	cin>>age;
	cout<<(long long)3.156e7 * age;
	return 0;
}

 



C.2的n次方计算 

题目描述

不使用累计乘法的基础上,通过移位运算(<<)实现2的n次方的计算。

输入描述:

多组输入,每一行输入整数n(0 <= n < 31)。

输出描述:

针对每组输入输出对应的2的n次方的结果。

示例1

输入

2 10

 

输出

4 1024

 

 
AC代码

#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <stdlib.h>
#include <algorithm>
using namespace std;

int main()
{
	int n;
	while(cin>>n) {
		int sum = 1;
		for(int i=0;i<n;i++)
		{
			sum = sum<<1;
		}
		cout<<sum<<endl;
	}
	return 0;
}

 



D.及格分数

题目描述

KiKi想知道他的考试分数是否通过,请帮他判断。从键盘任意输入一个整数表示的分数,编程判断该分数是否在及格范围内,如果及格,即:分数大于等于60分,是输出“Pass”,否则,输出“Fail”。

输入描述:

多组输入,每行输入包括一个整数表示的分数(0~100)。

输出描述:

针对每行输入,输出“Pass”或“Fail”。

示例1

输入

94

 

输出

Pass

 

示例2

输入

44

 

输出

Fail

 

 
AC代码

#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <stdlib.h>
#include <algorithm>
using namespace std;

int main()
{
	int s;
	cin>>s;
	if(s>=60) {
		cout<<"Pass";
	} else {
		cout<<"Fail";
	}
	return 0;
}

 


链接:https://ac.nowcoder.com/acm/contest/5904/E
来源:牛客网
 

题目描述

KiKi想知道从键盘输入的两个数的大小关系,请编程实现。

输入描述:

题目有多组输入数据,每一行输入两个整数(范围(1 ~231-1),用空格分隔。

输出描述:

针对每行输入,输出两个整数及其大小关系,数字和关系运算符之间没有空格,详见输入输出样例。

示例1

输入

1 1

 

输出

1=1

 

示例2

输入

1 0

1 0

输出

1>0

 

示例3

输入

0 1

 

输出

0<1

 

AC代码

#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <stdlib.h>
#include <algorithm>
using namespace std;

int main()
{
	int a,b;
	while(cin>>a>>b) {
		cout<<a;
		if(a==b) {
			cout<<"=";
		}else if(a>b){
			cout<<">";
		}else{
			cout<<"<";
		}
		cout<<b<<endl;
	}
	return 0;
}

 


 

 

题目描述

BMI指数(即身体质量指数)是用体重公斤数除以身高米数平方得出的数字,是目前国际上常用的衡量人体胖瘦程度以及是否健康的一个标准。例如:一个人的身高为1.75米,体重为68千克,他的BMI=68/(1.75^2)=22.2(千克/米^2)。当BMI指数为18.5~23.9时属正常,否则表示身体存在健康风险。编程判断人体健康情况。

输入描述:

一行,输入一个人的体重(千克)和身高(米),中间用一个空格分隔。

输出描述:

一行,输出身体Normal(正常)或Abnormal(不正常)。

示例1

输入

68 1.75

 

输出

Normal

 

示例2

输入

67.5 1.65

 

输出

Abnormal

 

AC代码

#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <stdlib.h>
#include <algorithm>
using namespace std;

int main()
{
	double w, h;
	while(cin>>w>>h){
		double BMI = w/(h*h);
		if(BMI<18.5 || BMI>23.9) {
			cout<<"Abnormal";
		}else{
			cout<<"Normal";
		}
		cout<<endl;
	}
	return 0;
}

 


 

题目描述

KiKi学习了循环,BoBo老师给他出了一系列打印图案的练习,该任务是打印用“*”组成的翻转直角三角形图案。

输入描述:

多组输入,一个整数(2~20),表示翻转直角三角形直角边的长度,即“*”的数量,也表示输出行数。

输出描述:

针对每行输入,输出用“*”组成的对应长度的翻转直角三角形,每个“*”后面有一个空格。

示例1

输入

5

 

输出

 

* * * * *
* * * *
* * *
* *
*

示例2

输入

6

 

输出

 

* * * * * *
* * * * *
* * * *
* * *
* *
*

AC代码

#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <stdlib.h>
#include <algorithm>
using namespace std;

int main()
{
	int len;
	while(cin>>len) {
		for(int i=0;i<len;i++)
		{
			for(int j=i;j<len;j++)
			{
				cout<<"* ";
			}
			cout<<endl;
		}
	}
	return 0;
}

 


 

题目描述

输入10个整数,分别统计输出正数、负数的个数。

输入描述:

输入10个整数(范围-231~231-1),用空格分隔。

输出描述:

两行,第一行正数个数,第二行负数个数,具体格式见样例。

示例1

输入

-1 2 3 -6 7 8 -1 6 8 10

 

输出

 

positive:7
negative:3


AC代码
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <stdlib.h>
#include <algorithm>
using namespace std;
const int N = 10;

int main()
{
	int i=0, tmp, zheng=0, fu=0;
	while(++i<=N && cin>>tmp) {
		if(tmp>=0) zheng++;
		else fu++;
	}
	cout<<"positive:"<<zheng<<endl;
	cout<<"negative:"<<fu;
	return 0;
}

 


 

题目描述

KiKi得到了两个n行m列的矩阵,他想知道两个矩阵是否相等,请你回答他。(当两个矩阵对应数组元素都相等时两个矩阵相等)。

输入描述:

 

第一行包含两个整数n和m,表示两个矩阵包含n行m列,用空格分隔。

从2到n+1行,每行输入m个整数(范围-231~231-1),用空格分隔,共输入n*m个数,表示第一个矩阵中的元素。

从n+2行到2n+1,每行输入m个整数(范围-231~231-1),用空格分隔,共输入n*m个数,表示第二个矩阵中的元素。

1 < n,m < 10

输出描述:

一行,如果两个矩阵相等输出"Yes"并换行,否则输出"No"并换行。

示例1

输入

 

2 2
1 2
3 4
1 2
3 4

输出

Yes

 

AC代码

#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <stdlib.h>
#include <algorithm>
using namespace std;

int main()
{
	int n, m, flag=1, temp;
	cin>>n>>m;
	int A[n][m];
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
		{
			cin>>A[i][j];
		}
	}
	
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
		{
			cin>>temp;
			if(temp != A[i][j]) {
				flag = 0;
				goto end; //跳出多重循环 
			}
		}
	}
	
end:
	if(flag) {
		cout<<"Yes"<<endl;
	} else {
		cout<<"No"<<endl;
	}
	return 0;
}

 


 
感想
感觉本练习赛的题目还是很基础的。

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

重剑DS

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值