• <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 張沈鵬 閱讀(323) 評論(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中  回復  更多評論   
             
            色综合久久中文字幕综合网| 久久99国产乱子伦精品免费| 久久国产免费| 久久无码专区国产精品发布| 欧美牲交A欧牲交aⅴ久久| 久久久久久久久久久久中文字幕 | 国内精品人妻无码久久久影院| 丰满少妇人妻久久久久久| 久久夜色tv网站| 亚洲AV伊人久久青青草原| 国产Av激情久久无码天堂| 久久精品国产精品亚洲| 午夜精品久久久久久毛片| 色综合久久综精品| 国产A三级久久精品| 久久精品国产亚洲精品| 久久精品国产亚洲AV忘忧草18| 热久久这里只有精品| 亚洲AV伊人久久青青草原| 国产精品青草久久久久婷婷| 亚洲午夜无码AV毛片久久| 久久不射电影网| 久久精品国产半推半就| 久久人妻无码中文字幕| 精品国产91久久久久久久a| 亚洲va中文字幕无码久久不卡| 激情久久久久久久久久| 久久久精品2019免费观看| 天天综合久久一二三区| 国产精品欧美久久久久天天影视| 久久精品国产亚洲av水果派| 国产精品99久久久久久宅男小说| 久久精品中文字幕有码| 国产福利电影一区二区三区久久久久成人精品综合 | 国产99久久久国产精品~~牛| 亚洲精品午夜国产VA久久成人| 亚洲国产成人精品无码久久久久久综合 | 久久久久久亚洲AV无码专区| 色悠久久久久久久综合网| 国产毛片久久久久久国产毛片| 亚洲午夜久久久精品影院|