• <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 張沈鵬 閱讀(320) 評論(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中  回復  更多評論   
             
            久久精品无码一区二区日韩AV| 精品久久久无码21p发布| 久久亚洲高清观看| 一级做a爱片久久毛片| 久久精品夜色噜噜亚洲A∨| 久久亚洲国产精品123区| 久久久久高潮综合影院| 国产精品一久久香蕉国产线看| 91精品无码久久久久久五月天| 一本久久综合亚洲鲁鲁五月天亚洲欧美一区二区 | 久久丫精品国产亚洲av不卡| 国产高潮国产高潮久久久91| 久久久久se色偷偷亚洲精品av| 国产精品久久永久免费| 欧美日韩精品久久免费| 亚洲精品乱码久久久久久自慰| 久久99免费视频| 亚洲精品无码久久久久| 狠狠色丁香婷婷综合久久来| 久久久久久久91精品免费观看| 亚洲伊人久久大香线蕉苏妲己| 国产精品乱码久久久久久软件 | 国产午夜精品久久久久免费视| 性高湖久久久久久久久AAAAA| 久久国产精品国产自线拍免费| 亚洲午夜无码久久久久| 亚洲国产精品无码久久久久久曰 | 精品国产91久久久久久久a| 色婷婷综合久久久久中文| 国产一区二区久久久| 久久天天躁狠狠躁夜夜2020| 久久中文娱乐网| 久久精品草草草| 色综合久久88色综合天天| 久久精品www人人爽人人| 亚洲香蕉网久久综合影视| 伊人久久大香线焦AV综合影院| 久久婷婷五月综合成人D啪| 久久精品国产2020| 久久久久亚洲AV无码观看| 亚洲精品97久久中文字幕无码|