yyyhhhyyy1 2021-10-20 08:06 采纳率: 83.3%
浏览 42
已结题

OJ上的问题运行错误不知道怎么搞

Sum of Numbers
自己感觉到代码没什么问题

img

#include <bits/stdc++.h>
using namespace std;

int main()
{
    string s;
    for (int i = 0; i >= 0; i++)
    {
        getline (cin , s);
        int a = s.length();
        int b = s.at(0);
        
        if (a==1&&b==0)
        break;
        
        else 
        {
            int c = 0;
            for (int j=0; j < a;j++)
            {
                c = 0 ;
                c = c + s.at(j); 
            }
            
            cout << c <<endl;
        }
    }
    return 0;
}

  • 写回答

1条回答 默认 最新

  • -Undefined_ 2021-10-20 08:14
    关注

    21行的c=0要去掉,每次加了一位数字后c又被变为0了

    觉得有用的话采纳一下答案哈

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 10月28日
  • 已采纳回答 10月20日
  • 创建了问题 10月20日