当前位置:网站首页>选拔赛题目代码
选拔赛题目代码
2022-06-28 06:21:00 【e..Gravity】
A题.求和
输入一个整数矩阵,计算位于矩阵边缘的元素之和。所谓矩阵边缘的元素,就是第一行和最后一行的元素以及第一列和最后一列的元素。输入格式第一行分别为矩阵的行数 m 和列数 n(m<100,n<100),两者之间以一个空格分开。
Input:
3 3
3 4 1
3 7 1
2 0 1
Output:
15
#include<iostream>
using namespace std;
int main()
{
int m,n;
cin>>m>>n;
int arr[100][100]={
0};
int sum=0;
for(int i=0;i<m;i++)
{
for(int j=0;j<n;j++)
{
cin>>arr[i][j];
if(i==0||i==m-1||j==0||j==n-1){
sum+=arr[i][j];
}
}
}
cout<<sum<<endl;
return 0;
}
B题.弹弹弹

#include<iostream>
using namespace std;
int main()
{
double h;
double sum=0,a;
cin>>h;
a=h/2.0;
sum=h;
for(int i=1;i<10;i++)
{
sum+=2.0*a;
a/=2.0;
}
cout<<sum<<endl;
cout<<a<<endl;
return 0;
}
C题.分数化小数

#include<iostream>
using namespace std;
int main()
{
int a, b, n;
cin >> a >> b >> n;
for (int i = 0; i < n; i++) {
a = a % b;
a *= 10;
}
cout << a / b << endl;
return 0;
}
这道题比赛时我用的数组,感觉啥情况都考虑了,还是过不了,
班上一大佬几行就解决了
D题.回文

#include<iostream>
#include<cstring>
using namespace std;
int main()
{
char arr[110];
cin>>arr;
bool flag=true;
int len=strlen(arr);
for(int i=0;i<len/2;i++)
{
if(arr[i]!=arr[len-1-i]){
flag=false;
}
}
if(flag){
cout<<"yes"<<endl;
}
else{
cout<<"no"<<endl;
}
return 0;
}
E题.小孩出列

#include<iostream>
using namespace std;
char arr[65][20];
int main()
{
int n, w, s;
char ch;;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
cin >> w >> ch >> s;
int count = 0;
w = w - 2;
while (count < n) {
for (int i = 0; i < s; i++) {
w = (++w) % n;
if (arr[w][18] == '1') {
i--;
}
}
cout << arr[w] << endl;
arr[w][18] = '1';
count++;
}
return 0;
}
F题.闭区间

#include<iostream>
#include<cstring>
#include<string>
int arr[10010];
using namespace std;
int main()
{
int n;
cin>>n;
int min_1=99999,max_1=-12;
for(int i=0;i<n;i++){
int a,b;
cin>>a>>b;
if(a<min_1){
min_1=a;
}
if(b>max_1){
max_1=b;
}
for(int j=a;j<=b;j++){
arr[j]=1;
}
}
bool flag=true;
for(int i=min_1;i<=max_1;i++)
{
if(arr[i]==0){
flag=false;
}
}
if(flag){
cout<<min_1<<" "<<max_1<<endl;
}
else{
cout<<"no"<<endl;
}
return 0;
}
I题.优秀奖

#include<iostream>
#include<algorithm>
using namespace std;
const int N = 1e5 + 10;
int arr[N];
int brr[N];
int n, m;
bool fun(int n)
{
int l = 0;
int r = m - 1;
while (l <= r) {
int mid = (l + r) >> 1;
if (brr[mid] < n) {
l = mid + 1;
}
else if (brr[mid] > n) {
r = mid - 1;
}
else {
return 1;
}
}
return 0;
}
int main()
{
cin >> n >> m;
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
for (int i = 0; i < m; i++) {
cin >> brr[i];
}
sort(brr, brr + m);
for (int i = 0; i < n; i++) {
if (fun(arr[i])) {
cout << arr[i] << " ";
}
}
return 0;
}
边栏推荐
- [untitled]
- Socket. Io long Connection Push, version Control, Real - Time Active user volume Statistics
- Lombok @equalsandhashcode annotation how to make objects The equals () method compares only some attributes
- Deleting MySQL under Linux
- 脚本语言和编程语言
- Yolact++ Pytorch环境
- 高质量国产立体声编解码器CJC8988,Pin to Pin替代WM8988
- 职场IT老鸟的几点小习惯
- AutoCAD C# 多段线自相交检测
- @The reason why the Autowired annotation is empty
猜你喜欢

Exception handling (I) -- null pointer and array index out of bounds

高质量国产立体声编解码器CJC8988,Pin to Pin替代WM8988

How to add live chat in your Shopify store?

cocoapod中的第三方库怎么引用本地头文件

Lombok @equalsandhashcode annotation how to make objects The equals () method compares only some attributes

Linked list (III) - reverse linked list

YYGH-BUG-03

Parsing ng template with let total in NZ Pagination

AutoCAD C# 多段线小锐角检测

Working principle of es9023 audio decoding chip
随机推荐
【Paper Reading-3D Detection】Fully Convolutional One-Stage 3D Object Detection on LiDAR Range Images
Xcode13.3.1 项目执行pod install后报错
自定义 cube-ui 弹出框dialog支持多个且多种类型的input框
Caused by: com. fasterxml. jackson. databind. Exc.invalidformatexception: exception resolution
Apple MDM bypass jailfree bypass MDM configuration lock free
death_satan/hyperf-validate
Camx架构开UMD、KMD log以及dump图的方式
4~20mA输入/0~5V输出的I/V转换电路
Use the SQL SELECT count distinct query statement to count the total number of unique values of a field in the database
Configure multiple database connections using the SSM framework
Scripting and programming languages
YYGH-BUG-02
Differences between overloads, rewrites, abstract classes and interfaces
图片按日期批量导入WPS表格
Taobao seo training video course [22 lectures]
Example of MVVM framework based on kotlin+jetpack
Is it safe to open a stock account? How to open a stock account?
Small ball playing
Shell script one click deployment (MySQL)
socke.io长连接实现推送、版本控制、实时活跃用户量统计