• <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中  回復  更多評論   
             
            久久亚洲AV无码精品色午夜麻豆| 国产成人精品久久| WWW婷婷AV久久久影片| 国产一区二区三区久久| 99久久精品免费看国产| 亚洲国产精品成人久久蜜臀 | 国产精品99久久免费观看| 日韩精品久久久久久免费| 99久久免费只有精品国产| 99久久国产亚洲综合精品| 亚洲中文字幕无码久久2017| 久久噜噜电影你懂的| 亚洲AⅤ优女AV综合久久久| 久久国产精品99精品国产987| 欧美激情精品久久久久久| 精品无码久久久久国产动漫3d| 国内精品久久国产大陆| 人妻中文久久久久| 996久久国产精品线观看| 久久精品成人欧美大片| 久久毛片免费看一区二区三区| 无码伊人66久久大杳蕉网站谷歌 | 狠狠色丁香婷综合久久| 久久久99精品一区二区| 久久精品这里热有精品| 五月丁香综合激情六月久久| 久久综合视频网站| 久久高清一级毛片| 99久久久久| 国产AV影片久久久久久| 久久香蕉综合色一综合色88| 国产Av激情久久无码天堂| 亚洲人成网亚洲欧洲无码久久| 性做久久久久久久久浪潮| 51久久夜色精品国产| 亚洲国产精品久久久久婷婷软件 | 72种姿势欧美久久久久大黄蕉| 伊人久久无码中文字幕| 亚洲国产成人久久综合野外| 亚洲午夜福利精品久久| 久久福利资源国产精品999|