标签:代码 http print out turn bsp max pac main
1012 数字分类 (20分)
https://pintia.cn/problem-sets/994805260223102976/problems/994805311146147840
四舍五入保留小数点后一位:
double Scale_4(double argu) { return floor(argu*10.0 + 0.5) / 10.0; }
代码:
#include <iostream> #include <cstdio> #include <cstring> #include <string> #include <cmath> #include <algorithm> using namespace std; int main() { bool flag=false; int n,arr[1002]; int sum1=0,sum2=0,sum3=0,sum4=0,sum5=0,max5=-1; double value=0; int i=0,j=0,k=0,count=0; cin>>n; for(i=0;i<n;i++) cin>>arr[i]; for(i=0;i<n;i++) { if((arr[i]%5==0)&&(arr[i]%2==0)) sum1+=arr[i]; else if(arr[i]%5==1) { k++; if(k%2==0) sum2-=arr[i]; else sum2+=arr[i]; } else if(arr[i]%5==2) sum3++; else if(arr[i]%5==3) {sum4+=arr[i];count++;} else if(arr[i]%5==4&&arr[i]>max5) max5=arr[i]; } if(count!=0) value=sum4*1.0/count; if(sum1!=0) cout<<sum1;else cout<<"N"; if(k>0) cout<<" "<<sum2;else cout<<" N"; if(sum3!=0) cout<<" "<<sum3;else cout<<" N"; if(sum4!=0) printf(" %.1f",floor(value*10.0 + 0.5) / 10.0);else cout<<" N"; if(max5!=-1) cout<<" "<<max5;else cout<<" N"; return 0; }
PTA乙级 (1012 数字分类 (20分),四舍五入小数点后一位)
标签:代码 http print out turn bsp max pac main
原文地址:https://www.cnblogs.com/jianqiao123/p/12253537.html