zoukankan      html  css  js  c++  java
  • BNUOJ 1011 人工智能?

    链接:http://www.bnuoj.com/bnuoj/problem_show.php?pid=1011

    简单题,..字符串查找

    注意有有小数出现

    #include <iostream>
    #include <string>
    #include <cstdlib>
    #include <cstdio>
    
    using namespace std;
    string data;
    int main()
    {
    	double translate(string tem);
    
    	string tem;
    	int t;
    	int i=1;
    	double power,vol,cur;			//功率,电压,电流.
    	cin>>t;
    	getchar();
    	while(t--)
    	{
    
    		getline(cin,data);
    		//cout<<data<<endl;
    		power=translate("P=");
    		vol=translate("U=");
    		cur=translate("I=");
    		cout<<"Problem #"<<i<<endl;
    		if(cur==0)
    			printf("I=%.2lfA
    ",power/vol);
    		if(vol==0)
    			printf("U=%.2lfV
    ",power/cur);
    		if(power==0)
    			printf("P=%.2lfW
    ",cur*vol);
    
    		cout<<endl;
    
    		i++;
    
    	}
    	return 0;
    }
    
    double translate(string tem)
    {
    	int first;
    	double ans;
    	first=data.find(tem,0);
    	tem.clear();
    	if (first!=string::npos)
    	{
    		first+=2;
    		while(data[first]>='0'&&data[first]<='9')
    		{
    			tem+=data[first];
    			first++;
    			if(data[first]=='.')
    			{
    				tem+=data[first];
    				first++;
    			}
    
    		}
    		ans=atof(tem.c_str());
    		if(data[first]=='m')
    			ans/=1000;
    		if(data[first]=='k')
    			ans*=1000;
    		if (data[first]=='M')
    			ans*=1000000;
    
    
    	}
    	else
    		ans=0;
    	return ans;
    
    }


     

  • 相关阅读:
    python面向对象开发
    python迭代器和生成器
    python 集合
    python 字典
    python 元组
    python列表
    python字符串方法
    dom节点操作
    vue 跨域配置代理 get/post 请求
    Vuecli版本调整
  • 原文地址:https://www.cnblogs.com/frankM/p/4399532.html
Copyright © 2011-2022 走看看