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


             
            久久久久亚洲AV片无码下载蜜桃| 成人综合伊人五月婷久久| 日本精品久久久久中文字幕 | 久久久久九国产精品| 青青热久久国产久精品| 热re99久久精品国99热| 激情久久久久久久久久| 一本色道久久88—综合亚洲精品| 国产成人精品久久一区二区三区| 久久综合狠狠综合久久激情 | 狠狠色丁香久久婷婷综合| 成人久久精品一区二区三区 | 亚洲中文字幕久久精品无码APP| 久久国产精品成人影院| 欧美精品丝袜久久久中文字幕| 亚洲欧美日韩久久精品第一区| 久久国产热这里只有精品| 国内精品久久久久久久97牛牛| 一极黄色视频久久网站| 7国产欧美日韩综合天堂中文久久久久 | 国产精品99久久久久久宅男小说| 国内精品久久人妻互换| 久久AV高潮AV无码AV| 亚洲?V乱码久久精品蜜桃| 久久精品无码一区二区app| 99久久久精品免费观看国产| 国产精品成人久久久| 亚洲国产成人久久精品99| 久久精品成人免费国产片小草| 国产精品久久久久久久久鸭| 色欲综合久久中文字幕网| 亚洲国产精品无码久久| 久久久久亚洲AV无码专区首JN| 久久精品亚洲男人的天堂| 久久久国产精华液| 国产免费福利体检区久久| 国产激情久久久久影院老熟女| 日韩精品久久久久久| 国产午夜福利精品久久| 久久久精品久久久久特色影视| 久久无码国产|