Codeforces 768A Oath of the Night's Watch
A. Oath of the Night's Watch
time limit per test:2 seconds
memory limit per test:256 megabytes
input:standard input
output:standard output
"Night gathers, and now my watch begins. It shall not end until my death. I shall take no wife, hold no lands, father no children. I shall wear no crowns and win no glory. I shall live and die at my post. I am the sword in the darkness. I am the watcher on the walls. I am the shield that guards the realms of men. I pledge my life and honor to the Night's Watch, for this night and all the nights to come." — The Night's Watch oath.
With that begins the watch of Jon Snow. He is assigned the task to support the stewards.
This time he has n stewards with him whom he has to provide support. Each steward has his own strength. Jon Snow likes to support a steward only if there exists at least one steward who has strength strictly less than him and at least one steward who has strength strictly greater than him.
Can you find how many stewards will Jon support?
Input
First line consists of a single integer n (1 ≤ n ≤ 105) — the number of stewards with Jon Snow.
Second line consists of n space separated integers a1, a2, ..., an (0 ≤ ai ≤ 109) representing the values assigned to the stewards.
Output
Output a single integer representing the number of stewards which Jon will feed.
Examples
Input
2
1 5
Output
0
Input
3
1 2 5
Output
1
Note
In the first sample, Jon Snow cannot support steward with strength 1 because there is no steward with strength less than 1 and he cannot support steward with strength 5 because there is no steward with strength greater than 5.
In the second sample, Jon Snow can support steward with strength 2 because there are stewards with strength less than 2 and greater than 2.
题目链接:http://codeforces.com/problemset/problem/768/A
分析:把数字排下序,取最大值和最小值,然后分别进行比较,用一个数去计算其个数即可!
下面给出AC代码:
1 #include <bits/stdc++.h>
2 using namespace std;
3 int main()
4 {
5 int n;
6 int a[100005];
7 while(scanf("%d",&n)!=EOF)
8 {
9 int ans=0;
10 for(int i=1;i<=n;i++)
11 scanf("%d",&a[i]);
12 sort(a+1,a+1+n);
13 if(n==1||n==2)
14 printf("0n");
15 if(n>=3)
16 {
17 int minn=a[1];
18 int maxn=a[n];
19 for(int i=2;i<=n-1;i++)
20 if(a[i]>minn&&a[i]<maxn)
21 ans++;
22 printf("%dn",ans);
23 }
24 }
25 return 0;
26 }
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- phpstudy漏洞分析原因到修复
- 哈?命令注入外带数据的姿势还可以这么骚?
- 记一次曲折的RCE挖掘
- pytest文档49-命令行参数--tb的使用
- pytest文档50-命令行参数--durations统计用例运行时间
- pytest文档51-内置fixture之cache使用
- pytest文档53-命令行实时输出错误信息(pytest-instafail)
- pytest文档52-命令行参数--setup-show查看fixture的执行过程
- pytest文档54-Hooks函数terminal打印测试结果(pytest_report_teststatus)
- SAS-免费的描述性统计程序自动化创建
- Godot游戏开发实践之四:搬运Unity的Pluggable AI教程
- TypeScript 4.1 新特性:字符串模板类型,Vuex 终于有救了?
- 使用 Node.js 定制你的技术雷达:上篇
- 使用 Node.js 定制你的技术雷达:中篇
- 大点干!早点散----------Redis从入门到精通!!!