• <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中  回復  更多評論   
             
            亚洲国产精品久久久久| 久久久久久国产精品美女| 久久亚洲AV成人无码| 精品国产青草久久久久福利| 国产精品久久久久a影院| 久久久久久夜精品精品免费啦| AV无码久久久久不卡蜜桃| 久久99精品国产99久久| 久久精品国产清自在天天线| 久久久久高潮综合影院| 国产99久久久久久免费看| 国产精品乱码久久久久久软件| 少妇精品久久久一区二区三区| 91久久成人免费| 性做久久久久久久| 亚洲乱码日产精品a级毛片久久| 久久久久久夜精品精品免费啦| 久久伊人亚洲AV无码网站| 色诱久久久久综合网ywww| 性高朝久久久久久久久久| 国产成人无码久久久精品一| 久久亚洲日韩看片无码| 香蕉久久一区二区不卡无毒影院| 亚洲欧美伊人久久综合一区二区| 久久精品成人免费观看97| 久久99精品久久久久久久不卡 | 久久久91人妻无码精品蜜桃HD| 久久精品aⅴ无码中文字字幕重口| 久久精品国产亚洲7777| 精品久久久久久| 精品久久人妻av中文字幕| 亚洲va中文字幕无码久久不卡| 性做久久久久久久久浪潮| 亚洲国产精品无码久久青草| 久久精品亚洲欧美日韩久久| 99久久精品免费看国产一区二区三区 | 午夜精品久久久久久| 久久九色综合九色99伊人| 久久久久亚洲AV无码专区桃色 | 天天爽天天爽天天片a久久网| 97久久超碰国产精品2021|