[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 给定一系列正整数,请按要求对数字进 ...
随机推荐
- 全排列+字符串查找|扑克排序|2014年蓝桥杯A组题解析第六题-fishers
标题:扑克序列 A A 2 2 3 3 4 4, 一共4对扑克牌.请你把它们排成一行. 要求:两个A中间有1张牌,两个2之间有2张牌,两个3之间有3张牌,两个4之间有4张牌. 请填写出所有符合要求的排 ...
- 三部排序|2013年蓝桥杯B组题解析第六题-fishers
三部排序| 一般的排序有许多经典算法,如快速排序.希尔排序等. 但实际应用时,经常会或多或少有一些特殊的要求.我们没必要套用那些经典算法,可以根据实际情况建立更好的解法. 比如,对一个整型数组中的数字 ...
- [转]otunnel:一个和lcx差不多的端口转发的工具
这是一个采用Golang编写的和lcx差不多的端口转发的工具,用来突破内网环境 项目地址 ooclab/otunnel 下载地址(内涵各大平台) http://dl.ooclab.com/otunne ...
- Winform选择目录路径与选择文件路径
https://blog.csdn.net/zaocha321/article/details/52528279 using System.Collections.Generic; using Sys ...
- oracle的loop等循环语句的几个用法小例子
--loop循环用法 (输出1到10) declare v_num number(2) := 0; begin loop v_num := v_num + 1; exit when v_num > ...
- 【译】第22节---Fluent API - EntityTypeConfiguration类
原文:http://www.entityframeworktutorial.net/code-first/entitytypeconfiguration-class.aspx 在我们开始使用Fluen ...
- 一、python (int & str 的方法)
1.变量:命名与使用 #!/usr/bin/env/ python # -*- coding:utf-8 -*- name = 'liQM' 只能包含字母.数字或下划线: 第一个字符不能是数字: 简短 ...
- java进程占用系统内存高,排查解决
转自:http://blog.51cto.com/chengxiaobai/2052530?cid=695076 故障:最近收到生产服务器的报警短信以及邮件,报警内容为:内存使用率高于70%. 使用t ...
- Spring中JdbcTemplate使用RowMapper
package com.cxl.demo.dao; import java.sql.ResultSet; import java.sql.SQLException; import java.util. ...
- C#6.0 语法
属性表达式 属性值初始化 public string name {get;set;} = "张三"; 函数表达式 NULL检查运算符 var aa = Created?.Date; ...