• <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中  回復  更多評論   
             
            7777精品伊人久久久大香线蕉| 无码精品久久久天天影视| 日本强好片久久久久久AAA| 亚洲人成网站999久久久综合| 狠狠色综合网站久久久久久久| 久久这里只有精品久久| 国内精品久久久久久野外| 精品国产乱码久久久久久郑州公司| 亚洲精品无码久久久久sm| 色婷婷久久综合中文久久蜜桃av| 77777亚洲午夜久久多人| 久久久久久精品免费看SSS| 一级女性全黄久久生活片免费| 日本WV一本一道久久香蕉| 亚洲午夜无码久久久久| 国内精品人妻无码久久久影院 | 成人亚洲欧美久久久久| 国产精品九九久久精品女同亚洲欧美日韩综合区 | 天堂久久天堂AV色综合| 久久精品亚洲一区二区三区浴池| 人妻无码αv中文字幕久久| 97久久精品午夜一区二区| 国产综合免费精品久久久| 亚洲а∨天堂久久精品| 亚洲欧美日韩久久精品第一区| 精品乱码久久久久久久| 99久久无码一区人妻| 99久久做夜夜爱天天做精品| 久久国产乱子伦免费精品| 久久人妻少妇嫩草AV蜜桃| 综合人妻久久一区二区精品| 97久久国产亚洲精品超碰热| 久久国产香蕉一区精品| 久久99精品久久久久久久久久| 狠狠久久综合| 久久精品一本到99热免费| 久久青青草原亚洲av无码| 99精品久久精品| 久久久国产打桩机| 国内精品久久久久国产盗摄| 久久99久久99精品免视看动漫|