• <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中  回復  更多評論   
             
            大香伊人久久精品一区二区| 久久精品无码一区二区app| 99久久国产宗和精品1上映| 色欲久久久天天天综合网精品| 久久久久久亚洲精品影院| 亚洲国产精品无码久久久蜜芽 | 欧美亚洲国产精品久久蜜芽| 天天爽天天爽天天片a久久网| 久久五月精品中文字幕| 奇米综合四色77777久久| 国产精品美女久久久久AV福利| 久久综合偷偷噜噜噜色| 国产精品美女久久久| 性做久久久久久久久老女人| 成人综合伊人五月婷久久| 亚洲国产精品无码久久久久久曰| 久久精品亚洲精品国产色婷 | 97久久精品人人做人人爽| 亚洲欧洲精品成人久久曰影片| 精品久久久久久亚洲精品| 性欧美大战久久久久久久| 亚洲一本综合久久| 久久亚洲春色中文字幕久久久 | 办公室久久精品| 色婷婷综合久久久久中文一区二区| 99久久国产综合精品网成人影院 | 欧美久久综合性欧美| 久久久久久国产精品免费无码 | 97久久综合精品久久久综合| 麻豆av久久av盛宴av| 久久亚洲中文字幕精品一区四| 四虎国产精品免费久久5151 | 青青热久久国产久精品| 91久久精品国产免费直播| 久久国产亚洲精品麻豆| 99久久免费国产精品热| 久久精品人人槡人妻人人玩AV| 少妇人妻88久久中文字幕| 久久婷婷五月综合色高清| 99久久夜色精品国产网站| 久久精品一区二区三区AV|