• <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>

            一道極其簡(jiǎn)單的ACM題,為什么第2段代碼通不過測(cè)試?
            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

            第一段代碼,通過測(cè)試
            # 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段代碼,通不過測(cè)試,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;
            }

            有時(shí)候第2段代碼會(huì)得出奇怪的結(jié)果,這是為什么?

            posted on 2006-04-19 01:48 張沈鵬 閱讀(324) 評(píng)論(2)  編輯 收藏 引用
            Comments
            • # re: 一道極其簡(jiǎn)單的ACM題,為什么第2段代碼通不過測(cè)試?
              任我行
              Posted @ 2006-04-20 08:24
              寫的真亂。下面寫法為什么意思?
              bool ignore=true;
              while(!istr.eof()){
              istr>>temp;
              if(ignore==true){
              ignore=false;
              continue;
              }
              array.push_back(temp);
              }
                回復(fù)  更多評(píng)論   
            • # re: 一道極其簡(jiǎn)單的ACM題,為什么第2段代碼通不過測(cè)試?
              me
              Posted @ 2006-04-22 16:04
              就是忽略第一個(gè)數(shù),把string轉(zhuǎn)為int放入vector中  回復(fù)  更多評(píng)論   

            只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


             
            欧美一区二区三区久久综合| 久久播电影网| 精品国产青草久久久久福利| 亚洲人AV永久一区二区三区久久| 亚洲精品无码专区久久同性男| 久久亚洲sm情趣捆绑调教| 精品熟女少妇a∨免费久久| 青青青青久久精品国产h| 国产精品成人久久久| 久久99国产亚洲高清观看首页 | 国内精品久久久久久久久电影网 | 久久久久久精品无码人妻| 久久亚洲AV成人无码国产| 久久精品亚洲乱码伦伦中文| 精品国产乱码久久久久久呢| 青青草原1769久久免费播放| 欧美日韩久久中文字幕| 国产日韩欧美久久| 久久99国产精品久久99果冻传媒| 久久经典免费视频| 久久久久亚洲精品中文字幕| 国产精品久久久久国产A级| 伊人久久无码精品中文字幕| 久久本道综合久久伊人| 香蕉久久一区二区不卡无毒影院| 国产亚洲美女精品久久久2020| 精品欧美一区二区三区久久久| 麻豆精品久久精品色综合| 欧美一区二区三区久久综合| 亚洲中文字幕无码久久精品1| 久久久网中文字幕| 国产精品激情综合久久| 亚洲国产成人久久综合一| 久久精品毛片免费观看| 97久久香蕉国产线看观看| 国内精品久久久久影院优| 久久久女人与动物群交毛片| 亚洲精品无码久久一线| 综合人妻久久一区二区精品| 亚洲AV无码成人网站久久精品大| 久久人妻少妇嫩草AV蜜桃|