时间限制: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. .Net Core项目添加日志功能

    一.微软内置的日志组件 在.Net Core中使用模板新建的Web Api项目时,会自动加入日志功能.只需要在控制器中注入ILogger就可以了.命名空间为:Microsoft.Extensions. ...

  2. FFmpeg内存IO模式(内存区作输入或输出)

    本文为作者原创,转载请注明出处:https://www.cnblogs.com/leisure_chn/p/10318145.html 所谓内存IO,在FFmpeg中叫作"buffered ...

  3. [SCOI2012] 喵星球上的点名

    Description 给定 \(N\) 个姓名串和 \(M\) 个点名串.询问每个点名串点到了多少姓名和每个姓名串被点到了几次.\(N\leq 5\cdot 10^4,M\leq 10^5\). S ...

  4. 如何在 ASP.NET Core 测试中操纵时间?

    有时候,我们会遇到一些跟系统当前时间相关的需求,例如: 只有开学季才允许录入学生信息 只有到了晚上或者周六才允许备份博客 注册满 3 天的用户才允许进行一些操作 某用户在 24 小时内被禁止发言 很显 ...

  5. activeX

    对外接口和classid在idl文件中,接口功能实现在ctrl类中实现

  6. Java中的集合迭代器

    集合的迭代器 任何集合都有迭代器. 任何集合类,都必须能以某种方式存取元素,否则这个集合容器就没有任何意义. 迭代器,也是一种模式(也叫迭代器模式).在java中它是一个对象,其目的是遍历并选中其中的 ...

  7. Java 快速排序法 冒泡排序法 选择排序法 插入排序法

    1.快速排序的原理: 选择一个关键值作为基准值.比基准值小的都在左边序列(一般是无序的),比基准值大的都在右边(一般是无序的). 从后往前比较,用基准值和最后一个值比较,如果比基准值小的交换位置,如果 ...

  8. Apollo源码阅读笔记(二)

    Apollo源码阅读笔记(二) 前面 分析了apollo配置设置到Spring的environment的过程,此文继续PropertySourcesProcessor.postProcessBeanF ...

  9. pygame编程之font模块

    方法一:pygame.font.Font(file, size=-1) 参数file:采用字体文件的路径,如果file参数设置为None则默认采用系统自带字体,如果自带字体文件无法打开就会报错: 参数 ...

  10. DOM事件-调用函数

    通过调用函数改变其内容: <!DOCTYPE html> <html lang="en" dir="ltr"> <head> ...