Problem A: Artificial Intelligence?
Description
Physics teachers in high school often think that problems given as text are more demanding than pure computations. After all, the pupils have to read and understand the problem first!
So they don't state a problem like ``U=10V, I=5A, P=?" but rather like ``You have an electrical circuit that contains a battery with a voltage of U=10V and a light-bulb. There's an electrical current of I=5A through the bulb. Which
power is generated in the bulb?".
However, half of the pupils just don't pay attention to the text anyway. They just extract from the text what is given: U=10V, I=5A. Then they think: ``Which formulae do I know? Ah yes, P=U*I. Therefore P=10V*5A=500W. Finished."
OK, this doesn't always work, so these pupils are usually not the top scorers in physics tests. But at least this simple algorithm is usually good enough to pass the class. (Sad but true.)
Today we will check if a computer can pass a high school physics test. We will concentrate on the P-U-I type problems first. That means, problems in which two of power, voltage and current are given and the third is wanted.
Your job is to write a program that reads such a text problem and solves it according to the simple algorithm given above.
Input
The first line of the input file will contain the number of test cases.
Each test case will consist of one line containing exactly two data fields and some additional arbitrary words. A data field will be of the form I=xA, U=xV or P=xW, where x is a real number.
Directly before the unit (A, V or W) one of the prefixes m (milli), k (kilo) and M (Mega) may also occur. To summarize it: Data fields adhere to the following grammar:
DataField ::= Concept '=' RealNumber [Prefix] Unit
Concept ::= 'P' | 'U' | 'I'
Prefix ::= 'm' | 'k' | 'M'
Unit ::= 'W' | 'V' | 'A'
Additional assertions:
The equal sign (`=') will never occur in an other context than within a data field.
There is no whitespace (tabs,blanks) inside a data field.
Either P and U, P and I, or U and I will be given.
Output
For each test case, print three lines:
a line saying ``Problem #k" where k is the number of the test case
a line giving the solution (voltage, power or current, dependent on what was given), written without a prefix and with two decimal places as shown in the sample output
a blank line
Sample Input
3
If the voltage is U=200V and the current is I=4.5A, which power is generated?
A light-bulb yields P=100W and the voltage is U=220V. Compute the current, please.
bla bla bla lightning strike I=2A bla bla bla P=2.5MW bla bla voltage?
Sample Output
Problem #1
P=900.00W Problem #2
I=0.45A Problem #3
U=1250000.00V
HINT
#include<stdio.h>
#include<string.h>
int main()
{
int n,t,i,k=1,x;
double P,U,I,b;
char a[1000];
scanf("%d",&n);
getchar();
x=n;
while(n--)
{
P=0;
U=0;
I=0;
gets(a);
t=strlen(a); for(i=0;i<t;i++)
{
b=1;
if(a[i]=='U'&&a[i+1]=='=')
{
i=i+2;
while(a[i]>='0'&&a[i]<='9')
{
U=U*10+a[i]-'0';
i++;
}
if(a[i]=='.')
{
i++;
while(a[i]>='0'&&a[i]<='9')
{
b=b*0.1;
U=U+b*(a[i]-'0');
i++;
}
}
if(a[i]=='m')
{
U=U/1000;
i++;
}
else if(a[i]=='k')
{
U=U*1000;
i++;
}
else if(a[i]=='M')
{
U=U*1000000;
i++;
}
}
else if(a[i]=='P'&&a[i+1]=='=')
{
i=i+2;
while(a[i]>='0'&&a[i]<='9')
{
P=P*10+a[i]-'0';
i++;
}
if(a[i]=='.')
{
i++;
while(a[i]>='0'&&a[i]<='9')
{
b=b*0.1;
P=P+b*(a[i]-'0');
i++;
}
}
if(a[i]=='m')
{
P=P/1000;
i++;
}
else if(a[i]=='k')
{
P=P*1000;
i++;
}
else if(a[i]=='M')
{
P=P*1000000;
i++;
} }
else if(a[i]=='I'&&a[i+1]=='=')
{
i=i+2;
while(a[i]>='0'&&a[i]<='9')
{
I=I*10+a[i]-'0';
i++;
}
if(a[i]=='.')
{
i++;
while(a[i]>='0'&&a[i]<='9')
{
b=b*0.1;
I=I+b*(a[i]-'0');
i++;
}
}
if(a[i]=='m')
{
I=I/1000;
i++;
}
else if(a[i]=='k')
{
I=I*1000;
i++;
}
else if(a[i]=='M')
{
I=I*1000000;
i++;
}
}
}
printf("Problem #%d\n",k);
if(P>0&&I>0)
printf("U=%.2lfV\n",P/I);
else if(P>0&&U>0)
printf("I=%.2lfA\n",P/U);
else if(U>0&&I>0)
printf("P=%.2lfW\n",U*I);
if(k!=x)
printf("\n");
k++;
}
return 0;
}
Problem A: Artificial Intelligence?的更多相关文章
- (转) Artificial intelligence, revealed
Artificial intelligence, revealed Yann LeCunJoaquin Quiñonero Candela It's 8:00 am on a Tuesday morn ...
- UVa 537 Artificial Intelligence?
题目大意:输入一个字符串,根据物理公式P=U*I,已知其中两个量,求第三个量,结果保留两位小数. Artificial Intelligence? Physics teachers in hig ...
- EECS 649 Introduction to Artificial Intelligence
EECS 649 Introduction to Artificial IntelligenceExamElectronic Blackboard Submission Due: April 24, ...
- (转)A curated list of Artificial Intelligence (AI) courses, books, video lectures and papers
A curated list of Artificial Intelligence (AI) courses, books, video lectures and papers. Updated 20 ...
- ARTIFICIAL INTELLIGENCE FOR GAMES (Ian Millington / John Funge 著)
相关网站:http://www.ai4g.com PART I AI AND GAMESCHAPTER1 INTRODUCTIONCHAPTER2 GAME AIPART II TECHNIQUESC ...
- Artificial intelligence(AI)
ORM: https://github.com/sunkaixuan/SqlSugar 微软DEMO: https://github.com/Microsoft/BotBuilder 注册KEY:ht ...
- Artificial Intelligence Language
Artificial Intelligence Language Objective We know, a true AI program should have ability to underst ...
- 拼写纠正 Artificial Intelligence: A Modern Approach
Artificial Intelligence: A Modern Approach http://mindhacks.cn/2008/09/21/the-magical-bayesian-metho ...
- Artificial Intelligence Research Methodologies 人工智能研究方法
Computer Science An Overview _J. Glenn Brookshear _11th Edition To appreciate the field of artificia ...
随机推荐
- 提示text还能输入多少字节
1.添加jQuery自定义扩展 $(function($){ // tipWrap: 提示消息的容器 // maxNumber: 最大输入字符 $.fn.artTxtCount = function( ...
- cdoj 邱老师看电影
//第一次写概率dp //写成记忆化搜索的形式比递推要更方便易懂 //不过好像还是可以写成递推的形式的 但是比较那个…… #include<cstdio> #include<iost ...
- sharepoint 2013 列表和库标签 元数据导航配置(2)
接前面提到的,如何创建一个术语库.sharepoint 2013 列表和库标签 元数据导航配置(1), 现在要做的,就是如何在自定义或者文档库中使用这个术语库,实现标签功能,通过这些标签,找到对应的文 ...
- Sequence operation(线段树区间多种操作)
Sequence operation Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...
- VB6关于判断模态窗体的问题
模态窗体也有人叫模式窗体,是否为模态窗体由Show方法的参数决定: 语法 object.Show style, ownerform Show 方法的语法包含下列部分: 部分 描述 object 可选的 ...
- Archlinux 安装配置指导 2015-05-24
因为用的Linode VPS的系统是Archlinux的,想在本地弄个系统做测试用,这样比较方便.然后发现自己在6年前做的一个Archlinux 安装配置Flash,好怀念的赶脚. 时过进迁,没想到A ...
- log4j.xml配置示例
这是log4j1.x版本讲解,log4j-1.2.16.jar 1. 一般的log4j.xml的两种配置方式: 1.Logger 完成日志信息的处理定义输出的层次和决定信息是否输出DEBUG&l ...
- ASP.NET MVC 必备知识点杂谈
一 工程结构4个程序集 Microsoft.Web.Mvc --一些可以使用的,不确定的程序包System.Web.Mvc --主程序库下面两个列入3.5的Net框架了System.Web.Abs ...
- C# Attribute(特性)之---数据契约 [DataContract]
服务契约定义了远程访问对象和可供调用的方法,数据契约则是服务端和客户端之间要传送的自定义数据类型. 一旦声明一个类型为DataContract,那么该类型就可以被序列化在服务端和客户端之间传送,如下所 ...
- C++11多线程
这篇文章说的很详细: https://www.ibm.com/developerworks/cn/linux/1412_zhupx_thread/