• <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久久国产主播综合精品 | 久久人人爽人人人人爽AV | 久久久亚洲精品蜜桃臀| 国产69精品久久久久99| 久久久久成人精品无码| 国产成人精品综合久久久久| 久久er国产精品免费观看2| 久久国产精品成人免费| 亚洲欧美国产精品专区久久| 国产亚洲综合久久系列| 久久久久久无码国产精品中文字幕| 久久婷婷色香五月综合激情| 色综合久久无码五十路人妻| 国产精品久久久久久久午夜片| 久久乐国产精品亚洲综合 | 国产综合久久久久久鬼色| 亚洲成人精品久久| av色综合久久天堂av色综合在| 亚洲精品国产字幕久久不卡| 91麻豆精品国产91久久久久久| 久久久久人妻一区二区三区| 亚洲国产精品久久| 国产精品久久久久影院色| 久久久久久久久久久精品尤物| 久久er国产精品免费观看2| 久久精品国产久精国产一老狼| 青青草国产精品久久| 一本一道久久综合狠狠老| 中文精品99久久国产| 精品久久久久久无码中文野结衣 | 国产精品一区二区久久精品无码| 久久精品国产乱子伦| 亚洲AⅤ优女AV综合久久久| 青青草原1769久久免费播放| 国产一久久香蕉国产线看观看| 久久精品水蜜桃av综合天堂| 伊人久久大香线蕉AV色婷婷色| 亚洲AV日韩AV永久无码久久| 中文字幕日本人妻久久久免费 | 久久国产福利免费| 亚洲国产精品久久久久网站|