• <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 張沈鵬 閱讀(327) 評論(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久久无毒不卡| 久久精品国产半推半就| 伊人精品久久久久7777| 久久久国产99久久国产一| 久久久一本精品99久久精品88| 亚洲国产精品嫩草影院久久| 午夜精品久久久内射近拍高清 | 日韩精品国产自在久久现线拍| 久久国产精品久久久| 爱做久久久久久| 99久久国产宗和精品1上映 | 久久久久无码精品国产| 久久久亚洲欧洲日产国码二区| 91麻豆精品国产91久久久久久| 久久九九久精品国产免费直播| 久久电影网一区| 欧美精品九九99久久在观看| 国产欧美一区二区久久| 中文字幕无码av激情不卡久久| 99精品伊人久久久大香线蕉| 久久亚洲sm情趣捆绑调教| 青青草原综合久久大伊人精品| 狠狠色丁香久久婷婷综合五月| 国产精品乱码久久久久久软件| 日本一区精品久久久久影院| 久久婷婷人人澡人人爽人人爱 | 久久狠狠色狠狠色综合| 久久亚洲sm情趣捆绑调教| 国产精品美女久久久免费| 麻豆成人久久精品二区三区免费 | 午夜人妻久久久久久久久| 伊人色综合久久天天| 99久久人妻无码精品系列蜜桃| MM131亚洲国产美女久久| 久久亚洲AV无码精品色午夜麻豆| 中文精品久久久久人妻| 一本一道久久a久久精品综合| 亚洲国产视频久久| 久久精品国产2020| 亚洲αv久久久噜噜噜噜噜|