各位大哥看看我哪错了?
Problem DescriptionYou 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
程序代码:
#include<iostream> #include<cstring> using namespace std; int main() { int i,j,n,test; char str[101]; scanf("%d",&test); while(test--) { scanf("%d\n",&n); double sum=0; int a[20]={0}; for(i=0;i<n;++i) { memset(str,0,sizeof(str)); gets(str); int nLen=strlen(str); for(j=0;j<nLen;++j) if(str[j]>='0'&&str[j]<='9') a[i]+=str[j]-'0'; } sum=a[0]; for(i=1;i<n;i++) sum=sum*a[i]/(sum+a[i]); printf("%.2lf\n",sum); } return 0; }
我结果是对的啊,怎么就错了呢?帮我看看错哪了,不要另写程序了,我只是想看看我该怎么改。。。。。。。。。。