【微软编程一小时】题目1 : Arithmetic Expression
描写叙述
Given N arithmetic expressions, can you tell whose result is closest to 9?
输入
Line 1: N (1 <= N <= 50000).
Line 2..N+1: Each line contains an expression in the format of "a op b" where a, b are integers (-10000 <= a, b <= 10000) and op is one of addition (+), subtraction (-), multiplication (*) and division (/). There is no "divided by zero" expression.
输出
The index of expression whose result is closest to 9. If there are more than one such expressions, output the smallest index.
例子输入
4
901 / 100
3 * 3
2 + 6
8 - -1
例子输出
2
每次都非常傻逼地用 == 去推断String相等,每次都吃亏都不长记性!
叫你不长记性!
import java.util.Scanner;
public class Main {
static int InversionCount ;
public static void main(String[] args)
{
int T,t;
Scanner jin = new Scanner(System.in);
T = jin.nextInt();
jin.nextLine();
int ret = T+1;
double max_abs = Double.MAX_VALUE;
for (t = 1; t <= T; t++) {
String line = jin.nextLine();
String[] argStrings = line.split(" ");
//System.out.println(argStrings.length);
double a = Double.parseDouble(argStrings[0]);
double b = Double.parseDouble(argStrings[2]);
double op_ret ;
if (argStrings[1].equals("+")) {
op_ret = a + b;
}
else if (argStrings[1].equals("-")) {
op_ret = a - b;
}
else if (argStrings[1].equals("*")) {
op_ret = a * b;
}
else op_ret = a / b;
if (Math.abs(op_ret - 9) < max_abs) {
max_abs = Math.abs(op_ret - 9);
ret = t;
}
}
System.out.println(ret);
}
}
【微软编程一小时】题目1 : Arithmetic Expression的更多相关文章
- 微软编程一小时 题目2: Longest Repeated Sequence
题目2 : Longest Repeated Sequence 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 You are given a sequence of i ...
- Longest Repeated Sequence【微软编程一小时-题目2】
时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 You are given a sequence of integers, A = a1, a2, ... an. A c ...
- 编程一小时 code.org [六一关注]
编程一小时活动的组织者是Code.org, 它是一个面向公众的公益组织,致力于在更多的学校推广计算机科学教育,并为女性和就业率低的有色人种学生学习计算机的机会.同时,一个空前强大的合作伙伴联盟也在支持 ...
- Programming pearls 编程珠玑的题目
Programming pearls 编程珠玑的题目 这段时间有空都在看编程珠玑,很经典的一本书,一边看一边用 python 做上面的题目,我做的都放到 github 上了 https://githu ...
- [UCSD白板题] Maximize the Value of an Arithmetic Expression
Problem Introduction In the problem, your goal is to add parentheses to a given arithmetic expressio ...
- C++编程显示四则运算题目
题目:C++编程显示四则运算题目 设计思路:(1)让用户自己确定出题的数量,同时显示加减乘除四则运算. (2)考虑到用户可能只会一种运算,因此可以选择运算.
- leetcode-Evaluate the value of an arithmetic expression in Reverse Polish Notation
leetcode 逆波兰式求解 Evaluate the value of an arithmetic expression in Reverse Polish Notation. Valid ope ...
- hihocoder Arithmetic Expression【在线查询】
Arithmetic Expression 时间限制:2000ms 单点时限:200ms 内存限制:256MB 描述 Given N arithmetic expressions, can you ...
- 结对编程(四则运算题目生成器core第七组)对接心得
在这篇博客博主想记录一下此次结队编程作业中与ui组对接的心得.在这里我也想表达一下对涂涵越同学的敬佩,他遇到困难时孜孜不倦求解的毅力着实让我佩服,我们在dll的生成上遇到了很大的困难,要不是他的坚持我 ...
随机推荐
- 手撕coreML之yolov2 object detection物体检测(含源代码)
一些闲话: 前面我有篇博客 https://www.cnblogs.com/riddick/p/10434339.html ,大致说了下如何将pytorch训练的.pth模型转换为mlmodel,部署 ...
- 使用css的-moz-element()把html元素当背景图片去
background:-moz-element(id)定义了一个从任意HTML元件产生的值.此图像是实时的,这意味着如果更改了HTML元素,则会自动更新使用结果值的CSS属性.element() &l ...
- python的Web框架,中间件middleware及djangoAdmin
简介 用于处理request和response的中间处理的函数,可以创建在项目中的任意位置,只要可以导入即可. 建议创建在APP目录下,方便管理. 函数范式与激活 中间件的范式: # 必须接受get_ ...
- 分布式计算框架Spark
Apache Spark是一个开源分布式运算框架,最初是由加州大学柏克莱分校AMPLab所开发. Hadoop MapReduce的每一步完成必须将数据序列化写到分布式文件系统导致效率大幅降低.Spa ...
- .NET常用开发工具整理
版本控制和项目管理工具 VisualSVN和AnkhSVN:两款在Visual Studio中管理Subversion的插件.. NuGet和NuGetPackageExplorer:一组用于自动执行 ...
- Mapreduce的api编程
KEYIN:输入的KEY是maptask所读取到的一行文本的起始偏移量,longVALUEIN:输入的VALUE的类型,输入的VALUE是maptask所读取到的一行文本内容,StringKEYOUT ...
- That Nice Euler Circuit(LA3263+几何)
That Nice Euler Circuit Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu D ...
- Jedis工具类代码
安装Redis可以参考 https://www.cnblogs.com/dddyyy/p/9763098.html Redis的学习可以参考https://www.cnblogs.com/dddyyy ...
- Jenkins 开启用户注册机制及用户权限设置
Jenkins 开启用户注册机制及用户权限设置 by:授客 QQ:1033553122 步骤 1. 系统管理-Configure Global Security 2. 设置
- 使用volley上传多张图片,一个参数对应多张图片,转载
https://my.oschina.net/u/1177694/blog/491834 原帖地址 而如果使用volley的话,因为请求数据那些都很简便,但遇到上传文件就麻烦那可不好,同时使用多个网络 ...