[PAT]数字分类
#include <stdio.h>
#include <stdlib.h> void A1(int *ar,int i);
void A2(int *ar,int i);
void A3(int *ar,int i);
void A4(int *ar,int i);
void A5(int *ar,int i); int main() { int i,n;
scanf("%d",&i);
int * ar =(int *)malloc(i*sizeof(int)); for(int j=; j<i; j++)
{
scanf("%d",&n);
ar[j]=n;
}
A1(ar,i);
A2(ar,i);
A3(ar,i);
A4(ar,i);
A5(ar,i);
return ;
} void A1(int *a,int l)
{
int sum=,count=;
for(int i=;i<l;i++)
{
if(a[i]%==)
{
count++;
sum+=a[i];
}
}
if(count==)
{
printf("N ");
} else
{
printf("%d ",sum);
}
} void A2(int *a,int l)
{
int result=,count=;
for(int j=;j<l;j++)
{
if(a[j]%==)
{
count++;
if(count%!=)
{
result+=a[j];
} else{
result-=a[j];
}
}
}
if(count==)
{
printf("N ");
} else
{
printf("%d ",result);
}
} void A3(int *a,int l)
{
int num=;
for(int j=;j<l;j++)
{
if(a[j]%==)
{
num++;
}
}
printf("%d ",num);
} void A4(int *a,int l)
{
int sum=,count=;
for(int j=;j<l;j++)
{
if(a[j]%==)
{
sum+=a[j];
count++;
}
}
if(count==)
{
printf("N ");
} else
{
printf("%.1f ",sum*1.0/count);
}
} void A5(int *a,int l)
{
int max=,count=;
for(int j=;j<l;j++)
{
if(a[j]%==)
{
count++;
if(a[j]>max)
{
max=a[j];
}
}
}
if(count==)
{
printf("N");
} else{
printf("%d",max);
} }
[PAT]数字分类的更多相关文章
- PAT乙级 1012. 数字分类 (20)
1012. 数字分类 (20) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 给定一系列正整数,请按要求对数字进 ...
- [C++]PAT乙级1012.数字分类 (20/20)
/* 1012. 数字分类 (20) 给定一系列正整数,请按要求对数字进行分类,并输出以下5个数字: A1 = 能被5整除的数字中所有偶数的和: A2 = 将被5除后余1的数字按给出顺序进行交错求和, ...
- 牛客网 PAT 算法历年真题 1002 :数字分类 (20)
1002 :数字分类 (20) 时间限制 1000 ms 内存限制 32768 KB 代码长度限制 100 KB 判断程序 Standard (来自 小小) 题目描述 给定一系列正整数,请按要求对数字 ...
- PAT 乙级 1012 数字分类 (20) C++版
1012. 数字分类 (20) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 给定一系列正整数,请按要求对数字进 ...
- PAT 1012 数字分类 (20)(代码+测试点)
1012 数字分类 (20)(20 分) 给定一系列正整数,请按要求对数字进行分类,并输出以下5个数字: A1 = 能被5整除的数字中所有偶数的和: A2 = 将被5除后余1的数字按给出顺序进行交错求 ...
- 【PAT】1012. 数字分类 (20)
1012. 数字分类 (20) 给定一系列正整数,请按要求对数字进行分类,并输出以下5个数字: A1 = 能被5整除的数字中所有偶数的和: A2 = 将被5除后余1的数字按给出顺序进行交错求和,即计算 ...
- PAT 乙级 1012.数字分类 C++/Java
题目来源 给定一系列正整数,请按要求对数字进行分类,并输出以下 5 个数字: A1 = 能被 5 整除的数字中所有偶数的和: A2 = 将被 5 除后余 1 的数字按给出顺序进行交错求和, ...
- PAT(B) 1012 数字分类(Java)
题目链接:1012 数字分类 代码 /** * Score 20 * Run Time 142ms * @author wowpH * @version 1.1 */ import java.util ...
- PAT-乙级-1012. 数字分类 (20)
1012. 数字分类 (20) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 给定一系列正整数,请按要求对数字进 ...
随机推荐
- P2147 [SDOI2008]洞穴勘测
P2147 [SDOI2008]洞穴勘测 思路 没办法,我就是喜欢板子都想发的人 都是基础操作,不多说了 代码 #include <bits/stdc++.h> #define ls ch ...
- Linux配置ssh服务和XShell连接Linux
SSH服务查看和安装,配置: https://www.cnblogs.com/qiuqiuqiu/p/6445426.html https://www.cnblogs.com/yunweis/p/77 ...
- Markdown语法参考
参考博客: https://www.jianshu.com/p/f3147a804368 https://www.jianshu.com/p/191d1e21f7ed https://www.jian ...
- NOIP队内凉心互测总结(8.22update)
8.22(结束后一天) __stdcall讲题qwq 全是CF原题 D1T1 一看像是结论题,打了下表,水过 没错就是结论题,直接暴力就好 D1T2 看起来不好做,没有AC思路 打了暴力 40分 T2 ...
- 查看kubernets上的image信息
# 查看pods所使用的image kubectl describe pods $podsname -n $namespace #获取containers.$containername.image i ...
- facebook api call——error
Error Codes send-api error-codes whatsapp api errors marketing-api error-reference graph-api/using-g ...
- Twitter开发2
There are different API families The standard (free) Twitter APIs consist of REST APIs and Streaming ...
- Kubernetes命令
kubectl applykubectl getkubectl set image deployment/xxx -n ns echoservice=xxxkubectl deletekubectl ...
- linux mysql操作命令大全
1.linux下启动mysql的命令:mysqladmin start/ect/init.d/mysql start (前面为mysql的安装路径) 2.linux下重启mysql的命令:mysqla ...
- springboot搭建环境整合jsp页面整合mybatis
1.pom文件依赖 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www ...