• <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中  回復  更多評論   
             
            久久妇女高潮几次MBA| 免费一级欧美大片久久网 | 日韩久久无码免费毛片软件| 久久久久久无码国产精品中文字幕 | 色综合久久综合网观看| 久久精品免费大片国产大片| 国产精品久久久久久久久久影院| 久久亚洲日韩精品一区二区三区| 精品国产乱码久久久久久郑州公司 | 免费久久人人爽人人爽av| 久久人人爽人人爽人人片av高请| 99久久国产综合精品网成人影院| 欧美国产成人久久精品| 美女写真久久影院| 久久精品国产亚洲AV香蕉| 久久亚洲精品无码播放| 国产精品一区二区久久国产| 亚洲国产精品嫩草影院久久 | 久久亚洲国产最新网站| 国産精品久久久久久久| 99久久99久久久精品齐齐| 国产69精品久久久久9999APGF| 一级做a爰片久久毛片16| 亚洲AV无码一区东京热久久| 久久婷婷五月综合成人D啪| 成人久久综合网| 久久久久久亚洲Av无码精品专口| 久久久久亚洲AV无码专区首JN| 精品久久人人爽天天玩人人妻| 国产成人久久AV免费| 国产成年无码久久久久毛片| 久久亚洲精品无码AV红樱桃| 亚洲成色WWW久久网站| 亚洲乱码精品久久久久.. | 精品久久久久成人码免费动漫| 99久久综合国产精品二区| 久久综合九色综合久99| 国产 亚洲 欧美 另类 久久| 中文精品久久久久国产网址| 久久夜色精品国产亚洲| 久久五月精品中文字幕|