| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 502 人关注过本帖
标题:各位大哥看看我哪错了?
只看楼主 加入收藏
cb_1212
Rank: 1
等 级:新手上路
帖 子:126
专家分:5
注 册:2011-4-28
结帖率:66.67%
收藏
已结贴  问题点数:10 回复次数:4 
各位大哥看看我哪错了?
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



程序代码:
#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;
}


我结果是对的啊,怎么就错了呢?帮我看看错哪了,不要另写程序了,我只是想看看我该怎么改。。。。。。。。。。
搜索更多相关主题的帖子: single 电阻 resistance several suppose 
2011-12-07 18:39
laoyang103
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:内蒙古包头
等 级:贵宾
威 望:19
帖 子:3082
专家分:11056
注 册:2010-5-22
收藏
得分:10 
Chinese please  或者你说下题意  然后发下题目网址

                                         
===========深入<----------------->浅出============
2011-12-07 18:59
cb_1212
Rank: 1
等 级:新手上路
帖 子:126
专家分:5
注 册:2011-4-28
收藏
得分:0 
回复 2楼 laoyang103
就是求并联电路的电阻。。。。--------2-----3--------就说明它电阻是5。。。
2011-12-07 19:04
cb_1212
Rank: 1
等 级:新手上路
帖 子:126
专家分:5
注 册:2011-4-28
收藏
得分:0 
回复 2楼 laoyang103
http://acm.hdu.

密码wsun
2011-12-07 19:05
cb_1212
Rank: 1
等 级:新手上路
帖 子:126
专家分:5
注 册:2011-4-28
收藏
得分:0 
回复 2楼 laoyang103
哦哦,我搞错了,只要输入数字大于9,我的程序就WA了,哈哈,大意了
2011-12-07 20:27
快速回复:各位大哥看看我哪错了?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.019926 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved