#18393: WA (line:58)


rmp4joxj6 (盧邊談話)


#0: 100% WA (line:58)

您的答案為: 960
正確答案為: 891

使用C++,程式碼如下:

#include <cmath>
#include <sstream>
#include <iostream>
using namespace std;
int main(){
  int sum,carry;
  bool check=true;
  string line,num;
  stringstream ss;
  while(getline(cin,line)){
    sum=0;
    ss.clear();
    ss<<line;
    while(!ss.eof()){
      ss>>num;
      for(int a=0;a<num.size();a++){
        if(!isdigit(num[a])){
          check=false;
          break;
        }
      }
      if(!check) check=true;
      else{
        carry=0;
        for(int a=num.size()-1;a>=0;a--) sum+=((num[a]-'0')*pow(10,carry)) , carry++;
      }
    }
    cout<<sum<<'\n';
  }
}

不知道少考慮了什麼,求助  -.-

#19739: Re:WA (line:58)


d10731308 (QWQ)


#0: 100% WA (line:58)

您的答案為: 960
正確答案為: 891

使用C++,程式碼如下:

#include
#include
#include
using namespace std;
int main(){
  int sum,carry;
  bool check=true;
  string line,num;
  stringstream ss;
  while(getline(cin,line)){
    sum=0;
    ss.clear();
    ss<<line;
    while(!ss.eof()){
      ss>>num;
      for(int a=0;a<num.size();a++){
        if(!isdigit(num[a])){
          check=false;
          break;
        }
      }
      if(!check) check=true;
      else{
        carry=0;
        for(int a=num.size()-1;a>=0;a--) sum+=((num[a]-'0')*pow(10,carry)) , carry++;
      }
    }
    cout<<sum<<'\n';
  }
}

不知道少考慮了什麼,求助  -.-

我本來跟你錯一樣的地方

後來在while(!ss.eof()){的下一行初始化num就過了

供參考