• <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中  回復  更多評論   
             
            久久毛片免费看一区二区三区| 成人国内精品久久久久一区| 国产精品青草久久久久福利99| 亚洲国产精品久久久久| 香蕉久久AⅤ一区二区三区| 久久久久99精品成人片欧美| 秋霞久久国产精品电影院| 欧美亚洲国产精品久久久久| 97久久精品国产精品青草| 亚洲国产精品狼友中文久久久| 狼狼综合久久久久综合网| 久久精品亚洲福利| 97热久久免费频精品99| 久久久无码精品亚洲日韩蜜臀浪潮| 国内精品九九久久久精品| 久久人人爽人人爽人人片av麻烦| 色综合久久中文综合网| 久久精品水蜜桃av综合天堂| 少妇熟女久久综合网色欲| 久久无码精品一区二区三区| 国产精品99久久久久久人| 亚洲精品乱码久久久久久按摩| 久久综合色老色| 人人狠狠综合久久亚洲高清| 曰曰摸天天摸人人看久久久| 久久成人国产精品| 久久婷婷国产综合精品| 久久亚洲私人国产精品| 无码人妻久久一区二区三区免费丨| 无码人妻少妇久久中文字幕 | 一级做a爰片久久毛片免费陪| 久久99精品国产| 色偷偷888欧美精品久久久| 国产欧美一区二区久久| 久久久久亚洲AV成人片| 久久久无码人妻精品无码| 精品综合久久久久久888蜜芽| 久久国产高潮流白浆免费观看| 久久综合88熟人妻| 精品久久久久久国产| 热久久这里只有精品|