• <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段代碼通不過(guò)測(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

            第一段代碼,通過(guò)測(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段代碼,通不過(guò)測(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段代碼通不過(guò)測(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段代碼通不過(guò)測(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   博問(wèn)   Chat2DB   管理


             
            亚洲国产精品婷婷久久| 国产高潮国产高潮久久久91 | 精品久久久久久无码中文野结衣 | 欧洲人妻丰满av无码久久不卡| 欧美一区二区三区久久综合| 久久精品99久久香蕉国产色戒| 久久九九有精品国产23百花影院| 国产A级毛片久久久精品毛片| 久久精品中文字幕一区| 久久精品国产AV一区二区三区 | 久久这里只有精品18| 久久精品国产只有精品66| 奇米综合四色77777久久| 久久青青草原亚洲av无码| 久久精品麻豆日日躁夜夜躁| 欧美午夜A∨大片久久 | 97久久久久人妻精品专区| 亚洲国产成人久久综合一区77 | 国产精品成人精品久久久| 久久天堂AV综合合色蜜桃网| 久久亚洲中文字幕精品一区四| 国产精品久久久久久吹潮| 免费久久人人爽人人爽av| 久久精品女人天堂AV麻| 99久久国产综合精品网成人影院 | 日本久久久久久中文字幕| 久久夜色精品国产欧美乱| 99久久国产亚洲综合精品| 久久久久久国产a免费观看不卡 | 久久久久久久久久久久久久| 久久99亚洲综合精品首页| 九九久久99综合一区二区| 久久婷婷五月综合国产尤物app| 狠狠色丁香久久婷婷综合_中 | 久久久久18| 久久久久亚洲av成人无码电影| 99精品久久久久久久婷婷| 99久久人人爽亚洲精品美女| 一本久久a久久精品综合夜夜| 久久精品国产91久久综合麻豆自制| 狠狠色婷婷久久一区二区三区|