• <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中  回復  更多評論   
             
            久久99国产精品成人欧美| 久久香蕉综合色一综合色88| 色播久久人人爽人人爽人人片aV| 久久―日本道色综合久久| 91精品久久久久久无码| 亚洲欧洲中文日韩久久AV乱码| 欧美亚洲国产精品久久高清 | 人妻无码中文久久久久专区| 精品久久久久久久无码| 久久精品视频91| 77777亚洲午夜久久多人| 色综合久久综合网观看| 国色天香久久久久久久小说| 精品综合久久久久久97超人| 国产精品久久久久久久人人看 | 亚洲欧美一级久久精品| 久久久久成人精品无码中文字幕| 久久久精品波多野结衣| 国产精品久久久久久影院 | 久久伊人精品青青草原高清| 亚洲а∨天堂久久精品| 久久国产高清字幕中文| 久久久免费精品re6| 奇米影视7777久久精品人人爽| 狠狠综合久久综合中文88 | 久久影视综合亚洲| 狠狠狠色丁香婷婷综合久久五月| 久久九九久精品国产免费直播| 久久婷婷五月综合成人D啪| 久久精品国产亚洲一区二区| A狠狠久久蜜臀婷色中文网| 人妻精品久久久久中文字幕一冢本| 青青久久精品国产免费看| 狠狠色丁香婷婷综合久久来来去 | 国产叼嘿久久精品久久| 久久综合久久综合久久| 一本大道久久a久久精品综合| 2021最新久久久视精品爱| 久久久久高潮毛片免费全部播放| 少妇高潮惨叫久久久久久| 久久精品免费一区二区|