Description

Given N arithmetic expressions, can you tell whose result is closest to 9?

Input

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.

Output

The index of expression whose result is closest to 9. If there are more than one such expressions, output the smallest index.

Sample Input

4
901 / 100
3 * 3
2 + 6
8 - -1

Sample Output

2
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <iterator>
using namespace std; int main(){
int n;
cin >> n;
vector<double> res(n,);
for(int i = ; i < n; ++ i){
double a,b;
char op;
cin >> a >> op >> b;
switch(op){
case '+':
res[i] = fabs(a+b-);
break;
case '-':
res[i] = fabs(a-b-);
break;
case '*':
res[i] = fabs(a*b-);
break;
case '/':
res[i] = fabs(a/b-);
break;
default:
break;
}
}
cout<<distance(res.begin(), min_element(res.begin(),res.end()))+<<endl;
return ;
}

ACM Arithmetic Expression的更多相关文章

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

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

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

  3. hihocoder Arithmetic Expression【在线查询】

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

  4. Arithmetic Expression

    时间限制:2000ms 单点时限:200ms 内存限制:256MB 描述 Given N arithmetic expressions, can you tell whose result is cl ...

  5. 【微软编程一小时】题目1 : Arithmetic Expression

    时间限制:2000ms 单点时限:200ms 内存限制:256MB 描写叙述 Given N arithmetic expressions, can you tell whose result is ...

  6. Variables and Arithmetic Expression

    Notes from The C Programming Language A decimal point in a constant indicates that it is floating po ...

  7. 【Codeforces 115D】Unambiguous Arithmetic Expression

    Codeforces 115 D 题意:给一个没有括号的表达式,问有多少种添加括号的方法使得这是一个合法的表达式?输入可能有正负号.加减乘除.数字. 思路1: 这是不能过的\(naive\)的\(dp ...

  8. ACM学习历程——UVA11234 Expressions(栈,队列,树的遍历,后序遍历,bfs)

    Description   Problem E: Expressions2007/2008 ACM International Collegiate Programming Contest Unive ...

  9. ACM学习历程——ZOJ 3829 Known Notation (2014牡丹江区域赛K题)(策略,栈)

    Description Do you know reverse Polish notation (RPN)? It is a known notation in the area of mathema ...

随机推荐

  1. 同一内网不能网段ping 不通

    [root@NB sysconfig]# route Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use ...

  2. Linux文件系统(inode、block……)

    内容源于<鸟哥的Linux私房菜> 认识 EXT2 文件系统 文件系统的特殊观察与操作 文件系统 superblock,inode,block superblock,inode,block ...

  3. SQLAlchemy Core中的异常及事务处理样码

    这部门内容比较简单,立存. #coding=utf-8 from datetime import datetime from sqlalchemy import (MetaData, Table, C ...

  4. ytu 2558: 游起来吧!超妹!(水题,趣味数学题)

    2558: 游起来吧!超妹! Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 7  Solved: 3[Submit][Status][Web Board ...

  5. MySQL5.6 on Windows 安装失败: String was not recognized as a valid DateTime

    在Win7,32位上安装MySQL5.6.21时出现日期/时间格式错误, 如下图所示: 错误描述为: String was not recognized as a valid DateTime. 下面 ...

  6. 来访统计的JS代码

    <script language="JavaScript"> var caution = false function setCookie(name, value, e ...

  7. windows7下安装php的imagick和imagemagick扩展教程

    这篇文章主要介绍了windows7下安装php的imagick和imagemagick扩展教程,同样也适应XP操作系统,Win8下就没测试过了,需要的朋友可以参考下 最近的PHP项目中,需要用到切图和 ...

  8. hdu 4033 2011成都赛区网络赛 余弦定理+二分 **

    二分边长,判断最后内角和是否为2pi,注意l与r的选取,保证能组成三角形 #include<cstdio> #include<iostream> #include<alg ...

  9. 5.linux内核模块基础,内核模块学习

    linux内核模块基础 一.定义 Linux 内核的整体结构非常庞大,其包含的组件也非常多,如何使用这些组件呢: 方法 1:把所有的组件都编译进内核文件,即:zImage 或 bzImage,但这样会 ...

  10. unity3D与网页的交互---做项目的一点总结

    (来自博客园) 由于项目需要,要求用unity来展示三维场景,并在三维中能够方便的查询数据库等.一开始尝试在unity中直接连接数据库,当时连的xml,然而每次发布成网页后都会出现路径找不到等问题,所 ...