微软编程一小时 题目1 : Arithmetic Expression
2014-04-05 20:11
387 查看
好久没写code了,bug好多%>_<%。
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<vector>
#include<string>
#include<cstring>
#include <cmath>
#include<algorithm>
using namespace std;
int N;
double a,b;
char c;
double mx=0x3f3f3f3f3f;
int ans=0;
double res=0;
int idx=0;
void cal()
{
switch(c)
{
case '+':
res=a+b;
break;
case '-':
res=a-b;
break;
case '*':
res=a*b;
break;
case '/':
res=a/b;
break;
}
}
int main()
{
// double s=3,d=3;
// double f=0;
// f=s*d;
// cout<<f;
//freopen("input.txt","r",stdin);
scanf("%d",&N);
// cout<<N<<endl;
for(int i=1;i<=N;i++)
{
//scanf("%d %c %d",&a,&c,&b);
cin>>a>>c>>b;
// cout<<a<<" "<<c<<" "<<b<<endl;
cal();
double tmp=abs(9-res);
// cout<<res<<" "<<mx<<" "<<tmp<<endl;
if(tmp<mx)
{
idx=i;
mx=tmp;
}
}
printf("%d\n",idx);
return 0;
}
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<vector>
#include<string>
#include<cstring>
#include <cmath>
#include<algorithm>
using namespace std;
int N;
double a,b;
char c;
double mx=0x3f3f3f3f3f;
int ans=0;
double res=0;
int idx=0;
void cal()
{
switch(c)
{
case '+':
res=a+b;
break;
case '-':
res=a-b;
break;
case '*':
res=a*b;
break;
case '/':
res=a/b;
break;
}
}
int main()
{
// double s=3,d=3;
// double f=0;
// f=s*d;
// cout<<f;
//freopen("input.txt","r",stdin);
scanf("%d",&N);
// cout<<N<<endl;
for(int i=1;i<=N;i++)
{
//scanf("%d %c %d",&a,&c,&b);
cin>>a>>c>>b;
// cout<<a<<" "<<c<<" "<<b<<endl;
cal();
double tmp=abs(9-res);
// cout<<res<<" "<<mx<<" "<<tmp<<endl;
if(tmp<mx)
{
idx=i;
mx=tmp;
}
}
printf("%d\n",idx);
return 0;
}
相关文章推荐
- 微软编程一小时 题目2: Longest Repeated Sequence
- 微软编程一小时题目一
- 2014微软编程一小时题目2 : Longest Repeated Sequence
- 算法 Longest Repeated Sequence(最大重复子序列 微软编程一小时 题目2)
- 微软编程一小时题目二
- 2014微软编程一小时题目1 : Arithmetic Expression
- 微软编程一小时 题目2 : Longest Repeated Sequence
- Longest Repeated Sequence【微软编程一小时-题目2】
- 微软编程一小时活动 - 暨微软2014实习生招募编程模拟测试 题目1 : Arithmetic Expression 原创解答
- 微软编程一小时题目1 : Arithmetic Expression
- 微软编程一小时比赛--题目1 : Arithmetic Expression
- 2014微软编程一小时 题目1 : Arithmetic Expression Java实现
- 【微软编程一小时】题目1 : Arithmetic Expression
- 微软2014编程之美初赛第一场——题目3 : 活动中心
- 微软编程之美的资格赛,这么简单的题目害我编了一个多小时——传话游戏
- CSDN高校俱乐部编程挑战群一道仅有7人通过的超5星微软比赛题目-------解题思路&优秀代码分享
- 微软推出《我的世界》“编程一小时”免费教程,携手Code.org普及计算机科学教育
- 微软2014编程之美初赛第一场——题目1 : 焦距
- 微软2014编程之美挑战赛初赛第二场 题目2 : 字符串压缩
- 微软编程之美的资格赛,这么简单的题目害我编了一个多小时——传话游戏