我的PAT-BASIC代码仓:https://github.com/617076674/PAT-BASIC

原题链接:https://pintia.cn/problem-sets/994805260223102976/problems/994805260990660608

题目描述:

PAT-BASIC1082——射击比赛

知识点:格式化输出

思路:按题述编程即可

注意:最后输出编号的时候需要格式化输出,前面补0至4位。

时间复杂度是O(N)。空间复杂度是O(1)。

C++代码:

#include<iostream>

using namespace std;

int main(){
	int N;
	cin >> N;
	
	int tempID;
	int tempX;
	int tempY;
	int tempDistance;
	
	int winnerID;
	int rookieID;
	
	int cloestDistance;
	int longestDistance;
	
	cin >> tempID >> tempX >> tempY;
	
	winnerID = tempID;
	rookieID = tempID;
	
	cloestDistance = tempX * tempX + tempY * tempY;
	longestDistance = tempX * tempX + tempY * tempY;
	
	for(int i = 1; i < N; i++){
		cin >> tempID >> tempX >> tempY;
		tempDistance = tempX * tempX + tempY * tempY;
		if(tempDistance < cloestDistance){
			winnerID = tempID;
			cloestDistance = tempDistance;
		}
		if(tempDistance > longestDistance){
			rookieID = tempID;
			longestDistance = tempDistance;
		}
	}
	
	printf("%04d %04d", winnerID, rookieID);
	
	return 0;
}

C++解题报告:

PAT-BASIC1082——射击比赛

 

相关文章:

  • 2022-12-23
  • 2022-01-04
  • 2021-10-15
  • 2021-08-15
  • 2022-12-23
  • 2021-04-29
猜你喜欢
  • 2021-08-19
  • 2021-07-09
  • 2022-01-15
  • 2021-12-03
  • 2022-02-05
  • 2021-09-15
相关资源
相似解决方案