• <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 張沈鵬 閱讀(320) 評論(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国内精品久久久久影院| 四虎国产精品免费久久5151| 国产精品视频久久久| 中文字幕亚洲综合久久2| 国产精品嫩草影院久久| 欧美大战日韩91综合一区婷婷久久青草 | 欧美伊人久久大香线蕉综合69 | 久久99久久99精品免视看动漫| 久久亚洲高清综合| 久久久一本精品99久久精品88| 久久精品国产亚洲精品2020| 国产精品成人无码久久久久久 | 亚洲国产精品无码久久久久久曰| 亚洲精品成人久久久| 97超级碰碰碰碰久久久久| 精品久久久无码21p发布| 色偷偷88欧美精品久久久| 97r久久精品国产99国产精| 久久精品国产亚洲av麻豆图片| 久久九九亚洲精品| 久久精品国产91久久麻豆自制| 久久国产色av免费看| 精品久久久一二三区| 无码人妻久久一区二区三区蜜桃 | 国产激情久久久久久熟女老人| 久久精品亚洲乱码伦伦中文| 国产精品九九久久免费视频 | 中文成人无码精品久久久不卡 | 久久精品成人一区二区三区| 青青青青久久精品国产h| 国产成人久久精品二区三区| 亚洲狠狠综合久久| 亚洲精品成人网久久久久久| 99久久免费国产精品特黄| 好属妞这里只有精品久久| 伊人色综合久久天天| 久久人人爽人人人人爽AV| www性久久久com| 久久久久亚洲精品天堂久久久久久 | 亚洲精品乱码久久久久久久久久久久|