#36682: c++ istringstream


yp11151049@yphs.tp.edu.tw (801-24)

學校 : 臺北市私立延平高級中學
編號 : 197224
來源 : [203.72.178.1]
最後登入時間 :
2024-01-16 09:26:24
d098. Stringstream運用練習(C++) -- 說明文件出自C++ Reference | From: [203.72.178.1] | 發表日期 : 2023-08-02 14:45

#include<bits/stdc++.h>
using namespace std;
int main(){
    string s,x;
    while(getline(cin,s)){
        int sum=0;
        istringstream in(s);
        while(in>>x){
            int temp=0;
            for(int i=0;i<x.size();i++){
                if(x[i]>=48 && x[i]<=57) temp=temp*10+(x[i]-48);
                else{temp=0;break;}
            }
            if(temp!=0) sum+=temp;
        }
        cout<<sum<<endl;
    }
    return 0;
}

 
ZeroJudge Forum