PAT乙級1012

題目鏈接

https://pintia.cn/problem-sets/994805260223102976/problems/994805311146147840

題解

就比較簡單,判斷每個數字是哪種情況,然后進行相應的計算即可。

下面的代碼中其實數組是不必要的,每取一個數字就可以直接進行相應計算。

// PAT BasicLevel 1012
// https://pintia.cn/problem-sets/994805260223102976/problems/994805311146147840#include <iostream>
using namespace std;int main()
{// 數字個數int n;cin >> n;// 獲取數字int* numArr=new int[n];for(int i=0;i<n;++i){cin >> numArr[i];}// 遍歷數組,計算A1至A5int a1=0,a1Count=0;int a2=0,flag=1,a2Count=0;int a3=0,a3Count=0;double a4Sum=0,a4Count=0;int a5=0,a5Count=0;for(int i=0;i<n;++i){switch(numArr[i]%5){case 0:if(numArr[i]%2==0){a1+=numArr[i];a1Count++;}break;case 1:a2+=flag*numArr[i];flag=-flag;a2Count++;break;case 2:a3++;a3Count++;break;case 3:a4Sum+=numArr[i];a4Count++;break;case 4:if(numArr[i]>a5){a5=numArr[i];a5Count++;}break;}}// 輸出A1至A5if(a1Count>0){cout << a1 << ' ';}else{cout <<"N ";}if(a2Count>0){cout << a2 << ' ';}else{cout << "N ";}if(a3Count>0){cout << a3 << ' ';}else{cout << "N ";}if(a4Count>0){printf("%.1lf ", a4Sum / a4Count);}else{cout << "N ";}if (a5Count > 0){cout << a5;}else{cout << 'N';}delete[] numArr;//system("pause");return 0;
}

作者:@臭咸魚

轉載請注明出處:https://www.cnblogs.com/chouxianyu/

歡迎討論和交流!


轉載于:https://www.cnblogs.com/chouxianyu/p/11300602.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/391885.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/391885.shtml
英文地址,請注明出處:http://en.pswp.cn/news/391885.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

我如何在昌迪加爾大學中心組織Google Hash Code 2019

by Neeraj Negi由Neeraj Negi 我如何在昌迪加爾大學中心組織Google Hash Code 2019 (How I organized Google Hash Code 2019 at Chandigarh University Hub) This is me !!! Neeraj Negi — Google HashCode Organizer這就是我 &#xff01;&#xff01;&#xff01; Neeraj …

leetcode 665. 非遞減數列(貪心算法)

給你一個長度為 n 的整數數組&#xff0c;請你判斷在 最多 改變 1 個元素的情況下&#xff0c;該數組能否變成一個非遞減數列。 我們是這樣定義一個非遞減數列的&#xff1a; 對于數組中所有的 i (0 < i < n-2)&#xff0c;總滿足 nums[i] < nums[i 1]。 示例 1: …

django基于存儲在前端的token用戶認證

一.前提 首先是這個代碼基于前后端分離的API,我們用了django的framework模塊,幫助我們快速的編寫restful規則的接口 前端token原理: 把(token加密后的字符串,keyname)在登入后發到客戶端,以后客戶端再發請求,會攜帶過來服務端截取(token加密后的字符串,keyname),我們再利用解密…

數據分布策略_有效數據項目的三種策略

數據分布策略Many data science projects do not go into production, why is that? There is no doubt in my mind that data science is an efficient tool with impressive performances. However, a successful data project is also about effectiveness: doing the righ…

cell 各自的高度不同的時候

1, cell 根據文字、圖片等內容&#xff0c;確定自己的高度。每一個cell有自己的高度。 2&#xff0c;tableView 初始化 現實的時候&#xff0c;不是從第一個cell開始顯示&#xff0c;&#xff08;從第二個&#xff1f;&#xff09;&#xff0c;非非正常顯示。 a:cell 的高度問題…

leetcode 978. 最長湍流子數組(滑動窗口)

當 A 的子數組 A[i], A[i1], …, A[j] 滿足下列條件時&#xff0c;我們稱其為湍流子數組&#xff1a; 若 i < k < j&#xff0c;當 k 為奇數時&#xff0c; A[k] > A[k1]&#xff0c;且當 k 為偶數時&#xff0c;A[k] < A[k1]&#xff1b; 或 若 i < k < j&…

spring boot源碼下載地址

github下載&#xff1a; https://github.com/spring-projects/spring-boot/tree/1.5.x git地址&#xff1a; https://github.com/spring-projects/spring-boot.git 因為項目中目前使用的就是spring boot 1.5.19版本&#xff0c;因此這里先研究spring boot 1.5版本源碼.轉載于:h…

java基礎學習——5、HashMap實現原理

一、HashMap的數據結構 數組的特點是&#xff1a;尋址容易&#xff0c;插入和刪除困難&#xff1b;而鏈表的特點是&#xff1a;尋址困難&#xff0c;插入和刪除容易。那么我們能不能綜合兩者的特性&#xff0c;做出一種尋址容易&#xff0c;插入刪除也容易的數據結構&#xff1…

看懂nfl定理需要什么知識_NFL球隊為什么不經常通過?

看懂nfl定理需要什么知識Debunking common NFL myths in an analytical study on the true value of passing the ball在關于傳球真實價值的分析研究中揭穿NFL常見神話 Background背景 Analytics are not used enough in the NFL. In a league with an abundance of money, i…

Docker初學者指南-如何創建您的第一個Docker應用程序

您是一名開發人員&#xff0c;并且想要開始使用Docker&#xff1f; 本文是為您準備的。 (You are a developer and you want to start with Docker? This article is made for you.) After a short introduction on what Docker is and why to use it, you will be able to cr…

mybatis if-else(寫法)

mybaits 中沒有else要用chose when otherwise 代替 范例一 <!--批量插入用戶--> <insert id"insertBusinessUserList" parameterType"java.util.List">insert into business_user (id , user_type , user_login )values<foreach collection…

spring—攔截器和異常

SpringMVC的攔截器 SpringMVC攔截器-攔截器的作用 Spring MVC 的攔截器類似于 Servlet 開發中的過濾器 Filter&#xff0c;用于對處理器進行預處理和后處理。 將攔截器按一定的順序聯結成一條鏈&#xff0c;這條鏈稱為攔截器鏈&#xff08;InterceptorChain&#xff09;。在…

29/07/2010 sunrise

** .. We can only appreciate the miracle of a sunrise if we have waited in the darkness .. 人們在黑暗中等待著&#xff0c;那是期盼著如同日出般的神跡出現 .. 附&#xff1a;27/07/2010 sunrise ** --- 31 July 改動轉載于:https://www.cnblogs.com/orderedchaos/archi…

密度聚類dbscan_DBSCAN —基于密度的聚類方法的演練

密度聚類dbscanThe idea of having newer algorithms come into the picture doesn’t make the older ones ‘completely redundant’. British statistician, George E. P. Box had once quoted that, “All models are wrong, but some are useful”, meaning that no model…

node aws 內存溢出_在AWS Elastic Beanstalk上運行生產Node應用程序的現實

node aws 內存溢出by Jared Nutt賈里德努特(Jared Nutt) 在AWS Elastic Beanstalk上運行生產Node應用程序的現實 (The reality of running a production Node app on AWS Elastic Beanstalk) 從在AWS的ELB平臺上運行生產Node應用程序兩年的經驗教訓 (Lessons learned from 2 y…

Day2-數據類型

數據類型與內置方法 數據類型 數字字符串列表字典元組集合字符串 1.用途 用來描述某個物體的特征&#xff1a;姓名&#xff0c;性別&#xff0c;愛好等 2.定義方式 變量名 字符串 如&#xff1a;name huazai 3.常用操作和內置方法 1.按索引取值&#xff1a;&#xff08;只能取…

嵌套路由

父組件不能用精準匹配&#xff0c;否則只組件路由無法展示 轉載于:https://www.cnblogs.com/dianzan/p/11308146.html

leetcode 992. K 個不同整數的子數組(滑動窗口)

給定一個正整數數組 A&#xff0c;如果 A 的某個子數組中不同整數的個數恰好為 K&#xff0c;則稱 A 的這個連續、不一定獨立的子數組為好子數組。 &#xff08;例如&#xff0c;[1,2,3,1,2] 中有 3 個不同的整數&#xff1a;1&#xff0c;2&#xff0c;以及 3。&#xff09; …

從完整的新手到通過TensorFlow開發人員證書考試

I recently graduated with a bachelor’s degree in Civil Engineering and was all set to start with a Master’s degree in Transportation Engineering this fall. Unfortunately, my plans got pushed to the winter term because of COVID-19. So as of January this y…

微信開發者平臺如何編寫代碼_編寫超級清晰易讀的代碼的初級開發者指南

微信開發者平臺如何編寫代碼Writing code is one thing, but writing clean, readable code is another thing. But what is “clean code?” I’ve created this short clean code for beginners guide to help you on your way to mastering and understanding the art of c…