zoukankan      html  css  js  c++  java
  • 求并联电阻值

    求并联电阻值

    Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other)
    Total Submission(s) : 28   Accepted Submission(s) : 15

    Font: Times New Roman | Verdana | Georgia 

    Font Size: ← →

    Problem Description

    You may be puzzled by the complicated circuits ever. Now let us simplify them. The task is: give you a parallel circuit(并联电路);
    you should calculate the resistance value (电阻)of it.
    You may suppose the parallel circuit is made up of several simple series circuits(简单的串联电路).

    Input

    The input contains several test cases. The first line of the input is a single integer T which is the number of test cases. T test cases follow. Each test case starts with a line contains only one integer n (0 < n <= 20), indicating the number of simple series circuits. Next n lines are the descriptions of each simple series circuit. The wire is consisted by the character “-”. And resistances are show by positive integers, means their resistance values. The line’s length is shorter than 100 characters, and the count of resistance in each simple series circuit is no more than 20. I assure all the calculations by integers using in this problem will not overflow the integer.

    Output

    For each case, please output the resistance value of the parallel circuit.

    Sample Input

    2
    1
    ---5----
    2
    ----2----3-1----
    ---2---2-------2-
    

    Sample Output

    5.00
    3.00

    ----------------------------------------------------------------------------------------------------------------------------
    解题思路:
      1.主要输入以字符串形式输入,将字符数字转换成整型数据时关键;
      2.'4' - '0' = 4;(将单个数字字符减去0字符,得到数字;
      3.还有多位数的判断;
    
    
     1 #include<stdio.h>
     2 #include<string.h>
     3 main()
     4 {
     5     int T,t,len,i,j,a;
     6     double sum1,sum2,m;
     7     char n[1000];
     8     scanf("%d",&T);
     9     while(T--)
    10     {
    11         sum2=0;
    12         scanf("%d",&t);
    13         for(i=0;i<t;i++)
    14         {
    15             sum1=0;a=0;
    16             scanf("%s",&n);
    17             len=strlen(n);
    18             for(j=0;j<len;j++)
    19             {
    20                 if(n[j]!='-')
    21                 {
    22                     m = n[j]-'0';      //将数字字符转换成纯数字;
    23                     a = a*10 + m;      //如果是相邻两个数字,要进行转换;
    24                 }
    25                 else
    26                 {
    27                     sum1 = sum1 + a;
    28                     a=0;
    29                 }
    30             }
    31             sum1 = sum1 + a;    //当最后一个数不是‘-’时,要加进sum1 ,否则会将最后一个数字漏掉
    32             sum2=sum2+1.0/sum1;
    33         }
    34         if(t==1)
    35         printf("%.2lf
    ",sum1);
    36         else
    37         printf("%.2lf
    ",1.0/sum2);
    38 
    39     }
    40 }


  • 相关阅读:
    浏览器渲染引擎工作原理
    js运行原理与机制
    新式网络浏览器幕后揭秘
    网站身份信息验证规则Cookie、Session、Token、JWT说明
    http简介
    react全家桶从0搭建一个完整的react项目(react-router4、redux、redux-saga)
    雅虎前端优化的35条军规
    服务端渲染与客户端渲染
    DataURL与File,Blob,canvas对象之间的互相转换的Javascript
    docker安装samba
  • 原文地址:https://www.cnblogs.com/yeshadow937/p/3876403.html
Copyright © 2011-2022 走看看