• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            一道極其簡單的ACM題,為什么第2段代碼通不過測試?
            http://acm.hziee.edu.cn/showproblem.php?pid=1096

            題目
            Your task is to calculate the sum of some integers.

            Input
            Input contains an integer N in the first line, and then N lines follow. Each line starts with a integer M, and then M integers follow in the same line.

            Output
            For each group of input integers you should output their sum in one line, and you must note that there is a blank line between outputs.

            Sample Input
            3
            4 1 2 3 4
            5 1 2 3 4 5
            3 1 2 3

            Sample Output
            10
            15
            6

            第一段代碼,通過測試
            # include <iostream>
            using namespace std;
            int main()
            {
            ?int m,n,s;
            ?int sum;
            ?cin>>n;
            ?for(int i=0;i<n;i++)
            ?{
            ??if(i)
            ???cout<<endl;
            ??cin>>m;
            ??sum=0;
            ??for(int j=0;j<m;j++)
            ??{
            ???cin>>s;
            ???sum+=s;
            ??}
            ??cout<<sum<<endl;
            ?}
            ?return 0;
            }

            第2段代碼,通不過測試,why?
            #include <iostream>
            #include <vector>
            #include <numeric>
            #include <string>
            #include <sstream>
            using namespace std;
            int main(void)
            {
            int times;
            cin>>times;
            while(times--!=-1){
            ??????? string str;
            ??????? istringstream istr;
            ??????? int temp;

            ??????? getline(cin,str);
            ??????? istr.str(str);
            ??????? vector<int> array;
            ???????
            ??????? bool ignore=true;
            ??????? while(!istr.eof()){
            ?????????? istr>>temp;??????????????????????????
            ?????????? if(ignore==true) {ignore=false;continue;}?????
            ?????????? array.push_back(temp);
            ?????????? }
            ??????? if(!array.empty()) cout<<accumulate(array.begin(), array.end(),0)<<"\n"<<endl;???
            ?}

            return 0;
            }

            有時候第2段代碼會得出奇怪的結果,這是為什么?

            posted on 2006-04-19 01:48 張沈鵬 閱讀(323) 評論(2)  編輯 收藏 引用
            Comments
            • # re: 一道極其簡單的ACM題,為什么第2段代碼通不過測試?
              任我行
              Posted @ 2006-04-20 08:24
              寫的真亂。下面寫法為什么意思?
              bool ignore=true;
              while(!istr.eof()){
              istr>>temp;
              if(ignore==true){
              ignore=false;
              continue;
              }
              array.push_back(temp);
              }
                回復  更多評論   
            • # re: 一道極其簡單的ACM題,為什么第2段代碼通不過測試?
              me
              Posted @ 2006-04-22 16:04
              就是忽略第一個數,把string轉為int放入vector中  回復  更多評論   
             
            久久无码人妻一区二区三区| 91精品无码久久久久久五月天| 久久亚洲国产成人影院网站 | 久久婷婷五月综合97色一本一本 | 国内精品伊人久久久久AV影院| 狠狠色丁香久久婷婷综| 久久精品视频91| 人妻精品久久久久中文字幕69| 国产叼嘿久久精品久久| 久久久久久久久久久久久久| 97久久国产亚洲精品超碰热 | 精品国产乱码久久久久久1区2区| 成人亚洲欧美久久久久| 午夜天堂精品久久久久| 日本高清无卡码一区二区久久 | 国产无套内射久久久国产| 亚洲国产精品无码成人片久久| 久久精品亚洲乱码伦伦中文| 97精品伊人久久大香线蕉app| 久久人人爽人人人人片av| 国产午夜精品久久久久九九| av无码久久久久不卡免费网站| 久久久这里有精品| 久久强奷乱码老熟女网站| 国产精品熟女福利久久AV| 精品九九久久国内精品| 亚洲午夜久久久久妓女影院 | 国产精品久久久久久久| 久久久久亚洲精品无码蜜桃| 国产亚洲精久久久久久无码77777| 久久久久国产一区二区三区| 国产精品久久久99| 99久久精品无码一区二区毛片 | 日本亚洲色大成网站WWW久久| 久久香蕉国产线看观看乱码| 久久ww精品w免费人成| 伊人久久大香线焦AV综合影院| 亚洲综合久久久| 2021国内久久精品| 久久亚洲国产精品成人AV秋霞| 亚洲精品97久久中文字幕无码|