时间限制:2000ms
单点时限:200ms
内存限制:256MB

描写叙述

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的更多相关文章

  1. 微软编程一小时 题目2: Longest Repeated Sequence

    题目2 : Longest Repeated Sequence 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 You are given a sequence of i ...

  2. Longest Repeated Sequence【微软编程一小时-题目2】

    时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 You are given a sequence of integers, A = a1, a2, ... an. A c ...

  3. 编程一小时 code.org [六一关注]

    编程一小时活动的组织者是Code.org, 它是一个面向公众的公益组织,致力于在更多的学校推广计算机科学教育,并为女性和就业率低的有色人种学生学习计算机的机会.同时,一个空前强大的合作伙伴联盟也在支持 ...

  4. Programming pearls 编程珠玑的题目

    Programming pearls 编程珠玑的题目 这段时间有空都在看编程珠玑,很经典的一本书,一边看一边用 python 做上面的题目,我做的都放到 github 上了 https://githu ...

  5. [UCSD白板题] Maximize the Value of an Arithmetic Expression

    Problem Introduction In the problem, your goal is to add parentheses to a given arithmetic expressio ...

  6. C++编程显示四则运算题目

    题目:C++编程显示四则运算题目 设计思路:(1)让用户自己确定出题的数量,同时显示加减乘除四则运算. (2)考虑到用户可能只会一种运算,因此可以选择运算.

  7. 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 ...

  8. hihocoder Arithmetic Expression【在线查询】

    Arithmetic Expression   时间限制:2000ms 单点时限:200ms 内存限制:256MB 描述 Given N arithmetic expressions, can you ...

  9. 结对编程(四则运算题目生成器core第七组)对接心得

    在这篇博客博主想记录一下此次结队编程作业中与ui组对接的心得.在这里我也想表达一下对涂涵越同学的敬佩,他遇到困难时孜孜不倦求解的毅力着实让我佩服,我们在dll的生成上遇到了很大的困难,要不是他的坚持我 ...

随机推荐

  1. python解析处理snmp回显----snmp

    查看服务端配置:https://www.cnblogs.com/dpf-10/p/9175409.html 查看内容示例: D:\python>snmpwalk -v 2c -c public ...

  2. Nginx反代Mogilefs分布式储存示例

    一.分布式存储系统简介 随着信息技术不断的发展,给我们带来便利的同时,不断增加的数据量级.信息之间的连接关联越来越复杂.数据访问的并发量日益增加对I/O的要求越来越高.数据类型越来越复杂等难题也成为信 ...

  3. 牛刀小试MySQL--日志文件

    牛刀小试MySQL--日志文件 MySQL Server的日志文件一共有五种类型的日志.(Innodb redo log除外,它属于Innodb存储引擎实现的日不在此篇讨论) The Error Lo ...

  4. MySQL实验准备(二)--Python模拟数据(MySQL数据库)

    Python模拟数据(MySQL数据库) 数据模拟 目的:模拟多个表的插入和查询数据的模拟,再通过基准测试脚本测试服务器性能和收集数据,仿真模拟. 备注: 如果需要基础的python环境,可以查看&l ...

  5. 流程控制<二>

    上一篇:Numbers.Strings.Lists 笔记<一>下一篇:数据结构-Python3.7<三> 如果需要修改迭代中的数据,建议先赋值一个副本(e.g:序列,切片复制的 ...

  6. 算法第四版-文字版-下载地址-Robert Sedgewick

    下载地址:https://download.csdn.net/download/moshenglv/10777447 算法第四版,文字版,可复制,方便copy代码 目录: 第1章 基 础 ...... ...

  7. [js高手之路]深入浅出webpack教程系列2-配置文件webpack.config.js详解(上)

    [js高手之路]深入浅出webpack教程系列索引目录: [js高手之路]深入浅出webpack教程系列1-安装与基本打包用法和命令参数 [js高手之路]深入浅出webpack教程系列2-配置文件we ...

  8. php中一个字符占用几个字节?

    先看看字符与字节有什么区别: (一)“字节”的定义 字节(Byte)是一种计量单位,表示数据量多少,它是计算机信息技术用于计量存储容量的一种计量单位. (二)“字符”的定义 字符是指计算机中使用的文字 ...

  9. [简记] github 上的 GraphQL v4 API

    突发奇想,想用github做一个支持rss的blog体系,或者就是知识管理体系,简单看了下,把测试用的暂存起来 # Type queries into this side of the screen, ...

  10. easyUI combobox combotree 模糊查询,带上下键选择功能,待完善。。。。

    /2017年4月9日 11:52:36 /** * combobox和combotree模糊查询 * combotree 结果带两级父节点(手动设置数量) * 键盘上下键选择叶子节点 * 键盘回车键设 ...