2019.12.31 Day1练习题

2019.12.31 Day1练习题寒假培训Day1

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE稳定放心使用

Part 1  二维数组

NEFU952 二维矩阵对角线和

#include<bits/stdc++.h>
using namespace std;
int m, a[15][15];
int main()
{
	while(cin>>m)
	{
		int cnt = 0;
		for(int i=1; i<=m; i++)
			for(int j=1; j<=m; j++)
				scanf("%d", &a[i][j]);
		for(int i=1; i<=m; i++)
			for(int j=1; j<=m; j++)
			{
				if(j==i || j==m-i+1) 
				{
					cnt += a[i][j];
					if(i == m-i+1)
						cnt += a[i][j];
					//cout<<i<<" "<<j<<endl;
				}
				
			}
		cout<<cnt<<endl;
	}
	return 0;
}

NEFU1064 矩阵的外围

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n, m, a[15][15];
	while(cin>>n>>m)
	{
		int sum = 0;
		for(int i=1; i<=n; i++)
			for(int j=1; j<=m; j++)
				cin>>a[i][j];
		for(int i=1; i<=m; i++)
		{
			sum += a[1][i];
			sum += a[n][i];
		}
		for(int i=2; i<n; i++)
		{
			sum += a[i][1];
			sum += a[i][m];
		}
		cout<<sum<<endl;
	}
	return 0;
}

NEFU955 五人帮

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int m, n, a[20][20], b[20][20];
	while(cin>>m>>n)
	{
		int maxn = -23;
		memset(a, 0, sizeof(a));
		for(int i=2; i<=m+1; i++)
			for(int j=2; j<=n+1; j++)
				cin>>a[i][j];
		for(int i=2; i<=m+1; i++)
			for(int j=2; j<=n+1; j++)
			{
				b[i][j] = a[i][j]+a[i-1][j]+a[i+1][j]+a[i][j-1]+a[i][j+1];
				maxn = max(b[i][j], maxn);
			}
		cout<<maxn<<endl;
	}
	return 0;
}

NEFU1031 回转小矩阵

#include<bits/stdc++.h>
using namespace std;
int n, m, a[110][110];
int main()
{
	while(cin>>n>>m)
	{
		for(int i=1; i<=n; i++)
			for(int j=1; j<=m; j++)
				cin>>a[i][j];
		for(int i=m; i>=1; i--)
		{
			for(int j=1; j<n; j++)
				cout<<a[j][i]<<" ";
			cout<<a[n][i]<<endl;
		}
	}
	return 0;
}

NEFU953 矩阵相加

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int m, n, a[15][15], b[15][15];
	while(cin>>m>>n)
	{
		for(int i=1; i<=m; i++)
			for(int j=1; j<=n; j++)
				cin>>a[i][j];
		for(int i=1; i<=m; i++)
			for(int j=1; j<=n; j++)
			{
				cin>>b[i][j];
				b[i][j] += a[i][j];
			}
		for(int i=1; i<=m; i++)
		{
			for(int j=1; j<n; j++)
				cout<<b[i][j]<<" ";
			cout<<b[i][n]<<endl;
		}
	}
	return 0;
}

NEFU951 二维矩阵最大值

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int m, n, a[15][15];
	while(cin>>m>>n)
	{
		int maxn=-2, flagx, flagy;
		for(int i=1; i<=m; i++)
			for(int j=1; j<=n; j++)
			{
				cin>>a[i][j];
				if(maxn < a[i][j])
				{
					maxn = a[i][j];
					flagx = i;
					flagy = j;
				}
			}
		cout<<flagx<<" "<<flagy<<" "<<maxn<<endl;
	}
	return 0;
}

NEFU954 矩阵相乘

#include<bits/stdc++.h>
using namespace std;
int n, a[20][20], b[20][20], c[20][20];
int main()
{
	while(cin>>n)
	{
		memset(c, 0, sizeof(c));
		for(int i=1; i<=n; i++)
			for(int j=1; j<=n; j++)
				scanf("%d", &a[i][j]);
		for(int i=1; i<=n; i++)
			for(int j=1; j<=n; j++)
				scanf("%d", &b[i][j]);
		for(int i=1; i<=n; i++)
			for(int j=1; j<=n; j++)
			{
				for(int k=1; k<=n; k++)
					c[i][j] += a[i][k]*b[k][j];
			} 
		for(int i=1; i<=n; i++)
		{
			for(int j=1; j<n; j++)
				printf("%d ", c[i][j]);
			cout<<c[i][n]<<endl;
		}
	}
	return 0;
}

Part 2 结构体

NEFU1053 结构体应用

#include<bits/stdc++.h>
using namespace std;
struct node{
	int no;
	char name[25];
	double score;
}st[100];
int main()
{
	int n;
	cin>>n;
	for(int i=1; i<=n; i++)
	{
		scanf("%d", &st[i].no);
		getchar();
		gets(st[i].name);
		//getchar();
		scanf("%lf", &st[i].score);
	}
	for(int i=1; i<=n; i++)
		printf("%d  %s  %.2lf\n" ,st[i].no, st[i].name, st[i].score);
	return 0;
}

NEFU1637 身高问题

#include<bits/stdc++.h>
using namespace std;
struct node{
	int no, hei;
	char name[25];
}st[110];
bool comp(node x, node y)
{
	if(x.hei != y.hei) return x.hei>y.hei;
	else return x.no<y.no;
}
int main()
{
	int n;
	cin>>n;
	for(int i=1; i<=n; i++)
		scanf("%s %d%d", st[i].name, &st[i].hei, &st[i].no);
	sort(st+1, st+n+1, comp);
	printf("%s %d %d", st[1].name, st[1].hei, st[1].no);
	return 0;
}

NEFU1638 成绩统计

 

#include<bits/stdc++.h>
using namespace std;
struct node{
	char flag, s1[6];
	int s2;
}num[1010];
int n, cnt=0, sum=0;
int main()
{
	cin>>n;
	for(int i=1; i<=n; i++)
	{
		cin>>num[i].flag;
		if(num[i].flag == 'C')
		{
			scanf("%s", num[i].s1);
			cnt++;
		}
		else
		{
			cin>>num[i].s2;
			sum += num[i].s2;
		}
	}
	cout<<cnt<<" "<<sum/(n-cnt);
	return 0; 
}

NEFU1186 优秀学生

#include<bits/stdc++.h>
using namespace std;
struct node{
	int no, sc;
	char name[21];
}st[110];
int n, cnt=0;
int main()
{
	while(cin>>n)
	{
		cnt = 0;
		for(int i=1; i<=n; i++)
		{
			scanf("%d %s %d", &st[i].no, st[i].name, &st[i].sc);
			if(st[i].sc >= 90)
			{
				cnt++;
				printf("%d %s %d\n", st[i].no, st[i].name, st[i].sc);
			}
		}
		cout<<cnt<<endl;
	}
	return 0;
} 

NEFU1147 谁不及格?

#include<bits/stdc++.h>
using namespace std;
struct node{
	char name[25], x[11];
	double quan;
}st[12];
int n, cnt=0;
int main()
{
	while(cin>>n)
	{
		cnt = 0;
		for(int i=1; i<=n; i++)
		{
			getchar();
			gets(st[i].name);
			//cin>>st[i].x;
			//cin>>st[i].quan;
			scanf("%s%lf", st[i].x, &st[i].quan);
			if(st[i].quan < 60.0)
				cnt++;
		}
		if(cnt)
		{
			cout<<cnt<<endl;
			/*
			for(int i=1; i<=n; i++)
			{
				if(st[i].quan < 60.0)
				{
					printf("%s\n%s\n%.2lf\n", st[i].name, st[i].x, st[i].quan);
				}
			}
			*/
			for(int i=1; i<=n; i++)
			{
				if(st[i].quan < 60.0)
					printf("%s\n", st[i].name);
			}
			for(int i=1; i<=n; i++)
			{
				if(st[i].quan < 60.0)
					printf("%s\n", st[i].x);
			}
			for(int i=1; i<=n; i++)
			{
				if(st[i].quan < 60.0)
					printf("%.2lf\n", st[i].quan);
			}
		}
		else cout<<"They are Great!!"<<endl;
	}
	return 0;
}

NEFU1188 两圆的距离

#include<bits/stdc++.h>
using namespace std;
struct yuan
{  
   double x;//圆心的X轴坐标
   double r;//半径
} data[11];
int n;
bool cmp(yuan a, yuan b)
{
	return a.x<b.x;
}
int main()
{
	while(cin>>n)
	{
		for(int i=1; i<=n; i++)
			cin>>data[i].x>>data[i].r;
		sort(data+1, data+1+n, cmp);
		printf("%.2lf\n", data[n].x-data[n].r);
	}
	return 0;
}

NEFU453 校庆的活动

#include<bits/stdc++.h>
using namespace std;
struct point{
	int x, y;
}a[60];
int n, xx, yy, flagx, flagy;
int main()
{
	while(cin>>xx>>yy)
	{
		cin>>n;
		double minn = 99999;
		for(int i=1; i<=n; i++)
		{
			cin>>a[i].x>>a[i].y;
			double l=sqrt((a[i].x-xx)*(a[i].x-xx)+(a[i].y-yy)*(a[i].y-yy));
			if(minn > l)
			{
				minn = l;
				flagx = a[i].x;
				flagy = a[i].y;
			}
		}
		cout<<flagx<<" "<<flagy<<endl;
	}
	return 0;
}

NEFU1184 第4题

#include<bits/stdc++.h>
using namespace std;
struct fushu{
	double shi, xu, he1, cha1, he2, cha2;
}num[2];
void cadd(fushu x1, fushu x2)
{
	void cprint1(fushu x);
	x1.he1 = x1.shi+x2.shi;
	x1.he2 = x1.xu+x2.xu;
	cprint1(x1);
}
void cminu(fushu x1, fushu x2)
{
	void cprint2(fushu x);
	x1.cha1 = x1.shi-x2.shi;
	x1.cha2 = x1.xu-x2.xu;
	cprint2(x1);
} 
void cprint1(fushu x)
{
	printf("%.2lf", x.he1);
	if(x.he2>=0) printf("+%.2lfi\n", x.he2);
	else printf("%.2lfi\n", x.he2);
}
void cprint2(fushu x)
{
	printf("%.2lf", x.cha1);
	if(x.cha2>=0) printf("+%.2lfi\n", x.cha2);
	else printf("%.2lfi\n", x.cha2);
}
int main()
{
	while(cin>>num[0].shi>>num[0].xu)
	{
		cin>>num[1].shi>>num[1].xu;
		cadd(num[0], num[1]);
		cminu(num[0], num[1]);
		//cprint(num[0]);
	}
	return 0;
}

By_Havoc.Wei

2019.12.31 Day1练习题2019.12.31 Day1练习题

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/180584.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • Python+opencv调用摄像头获取视频保存到本地并应用到YOLO中保存视频检测后的结果

    Python+opencv调用摄像头获取视频保存到本地并应用到YOLO中保存视频检测后的结果文章目录前言读写视频流获取摄像头:写入视频:完整的调用摄像头并保存视频代码应用到YOLO中总结前言之前的文章介绍了如何调用摄像头间隔拍照并保存图片(文章链接:Python+OpenCV调用摄像头固定间隔时间拍照并保存到本地同时应用到YOLO中检测目标),这篇文章再介绍一下如何调用摄像头并保存视频。读写视频流获取摄像头:capture=cv2.VideoCapture(0)ref,frame=capture.read()前文介绍过,cv2.VideoCapture()获取摄像头

    2022年6月22日
    31
  • mtk驱动安装_UBOOT下U盘驱动移植

    mtk驱动安装_UBOOT下U盘驱动移植对于MTKCamera驱动移植一般分为四部分:1、硬件IO口配置;2、Camera驱动移植;3、上电时序;4、修改i2c控制器;硬件电路:1、GPIO配置打开 mediatek\dct\DrvGen.exe 选择mediatek\custom\xiaoxi\kernel\dct\dct\codegen.

    2025年7月22日
    3
  • python做cae库_python常用模块-OS模块

    python做cae库_python常用模块-OS模块importos__file__:指当前文件,带有路径的D:/svn_auto3/test_case1/test1.py(注意这里的斜杠,和abspath的区别就是这里)#路径操作>>>os.chdir(‘D:\\’)#进入目录#目录切换操作>>>importos>>>os.curdir’.’>>>os.pardir’…

    2022年5月2日
    38
  • 机器学习方法:回归(三):最小角回归Least Angle Regression(LARS),forward stagewise selection

    机器学习方法:回归(三):最小角回归Least Angle Regression(LARS),forward stagewise selection前面两篇回归(一)(二)复习了线性回归,以及L1与L2正则——lasso和ridgeregression。特别描述了lasso的稀疏性是如何产生的。在本篇中介绍一下和lasso可以产生差不多效果的两种方法:stagewise和LARS

    2022年6月29日
    43
  • PotPlayer下载与使用

    PotPlayer下载与使用下载安装说起来,Potplayer的下载其实并不轻松,它在国内是没有自己的官网;虽然你简单百度下,总能找到下载网站,但是并不能保证其安全和纯净,个人建议从这个官网下载:下载入口:Potplayer官网/公众号分享Potplayer的官网提供有64位和32位两种版本,我们只需要选择好适合自己系统类型的版本,点击下载;一般系统都是64位,如果还不知道的自己电脑系统类型,那么右键桌面“我的电脑”图标,选择“属性”,进入之后,即可查看;下载完成后,得到一个exe文件,双击打开;依次点击“下一步

    2022年7月12日
    36
  • 使用 Python 爬取网页数据

    使用 Python 爬取网页数据在需要过去一些网页上的信息的时候 使用 Python 写爬虫来爬取十分方便 1 使用 urllib request 获取网页 urllib 是 Python 內建的 HTTP 库 使用 urllib 可以只需要很简单的步骤就能高效采集数据 配合 Beautiful 等 HTML 解析库 可以编写出用于采集网络数据的大型爬虫 注 示例代码使用 Python3 编写 urllib 是 Python2 中 urllib 和 urllib2 两个库合并而来 Python2 中的 urllib2 对应

    2025年8月11日
    5

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号