[acm]HDOJ 3082 Simplify The Circuit

题目地址:

http://acm.hdu.edu.cn/showproblem.php?pid=3082


字符串处理+并联电阻公式

 1 //11481261    2014-08-18 16:52:47    Accepted    3082    0MS    384K    733 B    G++    空信高手
 2 #include<string>
 3 #include<iostream>
 4 #include<cstdio>
 5 #include<cstdlib>
 6 
 7 using namespace std;
 8 
 9 int main()
10 {
11     //freopen("input.txt","r",stdin);
12     string str;
13     int Sum=0,nCases=0,count=0;
14     cin>>count;
15     double circuit=0;
16     while(count--)
17     {
18         cin>>nCases;
19         circuit=0;
20         while(nCases--)
21         {
22             cin>>str;
23             Sum=0;
24             int end = 0;
25             int pre = 0;
26             while(end<str.length())
27             {
28                 if(str[end]=='-')
29                     end++;
30                 else
31                 {
32                     pre=end;    
33                     while((str[end]!='-')&&(end<str.length()))
34                     {
35                         end++;
36                     }
37                     //字符串分割
38                     string str1 = str.substr(pre,end-pre);
39                     int i = atoi(str1.c_str());
40                     Sum+=i;
41                 }
42             }
43             circuit+=1.0/Sum;  //并联电阻公式
44         }
45         printf("%.2lf
",1.0/circuit);
46     }
47     
48     return 0;
49 }
原文地址:https://www.cnblogs.com/panweishadow/p/3919928.html