• <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 張沈鵬 閱讀(319) 評論(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中  回復  更多評論   
             
            久久精品国产男包| 久久久精品日本一区二区三区| 久久久久久国产a免费观看黄色大片| 亚洲成av人片不卡无码久久 | 久久久久亚洲av成人无码电影 | 国产69精品久久久久APP下载 | 久久99国产乱子伦精品免费| 久久99国产亚洲高清观看首页| 久久久久九九精品影院| 伊人久久大香线焦AV综合影院| 精品久久久久久国产| 香蕉久久影院| 久久这里只有精品久久| 久久久久久久波多野结衣高潮| 欧美精品一区二区精品久久| 久久精品国产亚洲av麻豆蜜芽| 日韩亚洲欧美久久久www综合网| 一本色道久久99一综合| 亚洲国产天堂久久综合| 亚洲国产精久久久久久久| 亚洲精品无码久久久久久| 精品无码久久久久久国产| 精品久久久久久中文字幕人妻最新| 久久久久久午夜精品| 久久国产精品免费| 99热热久久这里只有精品68| 国产V亚洲V天堂无码久久久| 狠狠色婷婷久久综合频道日韩| 欧美亚洲国产精品久久久久| 成人国内精品久久久久影院VR| 久久久久人妻精品一区| 精品久久久久久中文字幕大豆网| 久久影院午夜理论片无码| 久久久久国产亚洲AV麻豆| 久久e热在这里只有国产中文精品99 | 大蕉久久伊人中文字幕| 久久国产精品99久久久久久老狼 | 精品综合久久久久久888蜜芽| 日韩av无码久久精品免费| 久久综合噜噜激激的五月天| 欧洲人妻丰满av无码久久不卡|