#5272: 為什麼只有60分?


CSE911413 (David)

學校 : 國立臺中高級工業職業學校
編號 : 15788
來源 : [106.104.38.143]
最後登入時間 :
2018-11-28 23:34:44

#include <iostream>
using namespace std;
int main () {
    int a,b;
    while (cin >> a>> b) {
        int c=0;

    if(a>b){
        for (b;b<=a;b++)
            if (b%2==0){
              c+=b;
         }
        cout << c << endl;
      }

    else if(a<b){
         for (a;a<=b;a++)
            if (a%2==0){
              c+=a;
         }
        cout << c << endl;
      }
   }

    return 0;
}
 
 
 
 
 
 
請問為什麼程式執行沒有問題,也符合題目的要求,但還是只有60分??
懇請各位高見的幫助~ 
#5274: Re:為什麼只有60分?


popular10347 (ICPC// 哪時能唸到高等演算法T^T)

學校 : 元智大學
編號 : 11351
來源 : [1.169.118.99]
最後登入時間 :
2012-10-29 00:22:54

#include
using namespace std;
int main () {
    int a,b;
    while (cin >> a>> b) {
        int c=0;

    if(a>b){
        for (b;b<=a;b++)
            if (b%2==0){
              c+=b;
         }
        cout << c << endl;
      }

    else if(a
         for (a;a<=b;a++)
            if (a%2==0){
              c+=a;
         }
        cout << c << endl;
      }
   }

    return 0;
}
請問為什麼程式執行沒有問題,也符合題目的要求,但還是只有60分??
懇請各位高見的幫助~ 


如果a == b呢?
那就不會成立上面兩個if了
#5309: Re:為什麼只有60分?


CSE911413 (David)

學校 : 國立臺中高級工業職業學校
編號 : 15788
來源 : [106.104.38.143]
最後登入時間 :
2018-11-28 23:34:44

#include
using namespace std;
int main () {
    int a,b;
    while (cin >> a>> b) {
        int c=0;

    if(a>b){
        for (b;b<=a;b++)
            if (b%2==0){
              c+=b;
         }
        cout << c << endl;
      }

    else if(a
         for (a;a<=b;a++)
            if (a%2==0){
              c+=a;
         }
        cout << c << endl;
      }
   }

    return 0;
}
請問為什麼程式執行沒有問題,也符合題目的要求,但還是只有60分??
懇請各位高見的幫助~ 


如果a == b呢?
那就不會成立上面兩個if了
 
 
這題我解出來了,後來發現是要把">"改成">=",感謝!