• <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中  回復  更多評論   
             
            亚洲а∨天堂久久精品| 四虎国产精品免费久久久| 久久国产香蕉视频| 中文成人无码精品久久久不卡| 少妇熟女久久综合网色欲| 久久精品中文无码资源站| 久久久久亚洲精品日久生情| 久久婷婷国产综合精品| 久久精品国产72国产精福利| 亚洲va中文字幕无码久久| 国产成人精品综合久久久| 久久久亚洲裙底偷窥综合| 国产美女久久久| 久久久av波多野一区二区| 久久午夜电影网| 久久天天躁狠狠躁夜夜2020一 | 国产精品内射久久久久欢欢| 久久99国产精品久久99小说| 丰满少妇人妻久久久久久 | 久久se这里只有精品| 亚洲国产另类久久久精品小说| 国内精品久久久久久久亚洲| 亚洲乱码精品久久久久..| 久久人人爽人人爽人人片AV麻豆| 久久婷婷成人综合色综合| 国产精品美女久久福利网站| 久久人人爽人人爽AV片| 国产精品嫩草影院久久| 99久久国产综合精品成人影院| 久久九九精品99国产精品| 亚洲色大成网站WWW久久九九| 欧美黑人激情性久久| 婷婷久久综合九色综合绿巨人| 国产激情久久久久影院老熟女| 一级做a爰片久久毛片16| 91精品国产91久久综合| 久久综合给合久久狠狠狠97色| 色综合久久久久无码专区| 亚洲中文字幕无码一久久区| 亚洲日本va中文字幕久久| 久久婷婷国产综合精品|