时间限制: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. 几种好用的经典webshell(php)

    php经典一句话: <?php echo shell_exec($_GET['cmd']);?> 中国菜刀:官网:www.maicaidao.co原理:上传一句话(<?php @ev ...

  2. .net core Identity集成IdentityServer4 (1)基本操作

    一. 新建asp.net core identity项目 新建项目->asp.net core web应用程序-> web应用程序(模型视图控制器)&更改身份验证为个人. 新建一个 ...

  3. layui 文字滚动

    将消息标题滚动 上面是效果 <li class="layui-nav-item"> <div class="layui-carousel" i ...

  4. 修改mysql忽略大小写

    mysql -p --1.登录mysql show variables like "%case%";+------------------------+-------+| Vari ...

  5. win10 管理工具中添加 oracle 10g驱动

    重装了系统,在应用oracle 10g时,一直在管理工具中没有添加成功ODBC驱动,今天找到解决方法了. 状态如下: 解决方法: c盘——windows——SysWOW64——odbcad32.exe ...

  6. Java中 接口是如何实现多态的特性的

    Java中多态是个很难理解的概念,但同时又是非常重要的概念,Java三大特性(封装.继承.多态)之一,我们从字面上理解,就是一种类型的多种状态,一下通过卖小汽车的例子再次说明什么是多态,其中利用到了接 ...

  7. 【Spring】19、spring配置数据源的4种方式

    不管采用何种持久化技术,都需要定义数据源.Spring中提供了4种不同形式的数据源配置方式: spring自带的数据源(DriverManagerDataSource),DBCP数据源,C3P0数据源 ...

  8. 使用Twitter异常检测框架遇到的坑

    在Github上搜索“Anomaly Detection”,Twitter的异常检测框架(基于R语言)高居榜首,可见效果应该不错: 但是活跃度并不高,3-4年没人维护了: 因此在使用时难免会遇到一些坑 ...

  9. ​《数据库系统概念》4-DDL、集合运算、嵌套子查询

    一.DDLa) SQL Data DefinitionSQL的基本数据类型有char(n).varchar(n).int.smallint.numeric(p,d).real,double preci ...

  10. 云卡门禁安卓SDK_BLEDOOR_SDK_ANDROID_2016_12_15

    package com.bosk.bledoor.sdk; //sdk包的开门服务类,AndroidManifest.xml 必须注册 //<service //android:name=&qu ...