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


             
            精品久久久久久中文字幕人妻最新| 久久亚洲国产成人影院网站| 亚洲αv久久久噜噜噜噜噜| 久久w5ww成w人免费| 国产成人99久久亚洲综合精品| 日本欧美国产精品第一页久久| 97精品依人久久久大香线蕉97| 国产午夜福利精品久久2021| 青青草原综合久久大伊人精品| 性高朝久久久久久久久久| 精品熟女少妇av免费久久| 香港aa三级久久三级老师2021国产三级精品三级在 | 久久人人爽人人爽人人片AV麻豆| 国产美女亚洲精品久久久综合| 久久精品国产免费一区| 久久99热这里只有精品国产| 精品综合久久久久久88小说| 色综合久久无码五十路人妻| 久久久国产一区二区三区| 久久精品一本到99热免费| 精品久久久一二三区| 国产精自产拍久久久久久蜜| 囯产极品美女高潮无套久久久| 久久久艹| 午夜视频久久久久一区 | 国产精品久久久天天影视香蕉| 国产成人久久精品一区二区三区| 伊人久久综在合线亚洲2019| 97久久超碰成人精品网站| 亚洲色欲久久久综合网东京热| 欧美激情精品久久久久久| 精品久久久久久无码中文野结衣| 久久91精品国产91久久户| 日本欧美久久久久免费播放网| 久久精品国产亚洲AV香蕉| 伊人热热久久原色播放www| 伊色综合久久之综合久久| 久久久久久久久久久久久久| 精品多毛少妇人妻AV免费久久| 久久精品无码免费不卡| 久久伊人五月天论坛|