| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 332 人关注过本帖
标题:不明白BUG在哪 求大神指导!
只看楼主 加入收藏
bbb222
Rank: 2
等 级:论坛游民
帖 子:31
专家分:54
注 册:2012-11-17
结帖率:77.78%
收藏
已结贴  问题点数:10 回复次数:3 
不明白BUG在哪 求大神指导!
#include <iostream>

using namespace std;

int main()
{
    string a,b;
    while(cin >> a >> b)
    {
        if(a == "0"&&b == "0")
            return 0;
        int a1 = a.length();
        int b1 = b.length();
        int num;
        int h;
        if(a1 > b1)
        {
            num = b1;
            h=1;
        }
        if(a1 < b1)
        {
            num = a1;
            h=2;
        }
        if(a1 == b1)
        {
            num = a1;
            h = 0;
        }
        int temp = 0, count = 0;
        for(int i = 0; i < num; i++)
        {
            if(a[a1-i-1]+b[b1-i-1]+temp-96>9)
            {
                count++;
                temp = 1;
                continue;
            }
            temp = 0;
        }
        if(temp == 1 )
        {
            if(h==1)
            {

                for(int i = 1; i < a1-num+1 ; i++)
                 {
                    if(a[a1-num-i]=='9')
                    {
                        count++;
                    }
                    if(a[a1-num-i]!='9')
                    {
                        break;
                    }
                }
            }
            if(h==2)
            {
                 for(int i = 1; i < b1 -num+1 ; i++)
                 {
                    if(b[b1-num-i]=='9')
                    {
                        count++;
                    }
                    if(b[b1-num-i]!='9')
                    {
                        break;
                    }
                 }
            }
            if(h == 0);
        }
        if(count != 0)
            cout << count << " carry operations." << endl;
        if(count == 0)
            cout << "No carry operation." << endl;
    }
    return 0;
}
Children are taught to add multi-digit numbers from right-to-left one digit at a time. Many find the "carry" operation - in which a 1 is carried from one digit position to be added to the next - to be a significant challenge. Your job is to count the number of carry operations for each of a set of addition problems so that educators may assess their difficulty.
Each line of input contains two unsigned integers less than 10 digits. The last line of input contains 0 0. For each line of input except the last you should compute and print the number of carry operations that would result from adding the two numbers, in the format shown below.

Sample Input
123 456
555 555
123 594
0 0

Output for Sample Input
No carry operation.
3 carry operations.
1 carry operation.

题目如上...不知道错在那里...怎么样也不能提交...
POJ2562 TOJ1350 求大神指导!!!
搜索更多相关主题的帖子: include return 
2012-11-17 20:48
bbb222
Rank: 2
等 级:论坛游民
帖 子:31
专家分:54
注 册:2012-11-17
收藏
得分:0 
自己给自己灌水...
求大神能指导一下 哪里有问题啊?
2012-11-17 20:59
青春无限
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:江苏
等 级:贵宾
威 望:24
帖 子:3451
专家分:19340
注 册:2012-3-31
收藏
得分:10 
看看

学 会看代码…学习写程序…学会搞开发…我的目标!呵呵是不是说大话啊!!一切皆可能
2012-11-17 21:07
bbb222
Rank: 2
等 级:论坛游民
帖 子:31
专家分:54
注 册:2012-11-17
收藏
得分:0 
已经找到问题,输出问题...
谢谢青春无限、
2012-11-17 21:56
快速回复:不明白BUG在哪 求大神指导!
数据加载中...
 
   



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

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