解题的小问题(C++)

1.判断一个数是否为整数  if(m==(int)m)

2.#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,m;
    scanf("%d%d",&n,&m);
    int a[n];
    float count = 0;
    for(int i = 0; i < n; i++){
        scanf("%d",&a[i]);
    }
    for(int j = 0; j < n-m; j++){
        int temp = 0;
        int k = j;
        while(k < j+m){
            temp += a[k];
            k++;
        }
        if(temp > count){
            count = temp;
        }
    }
    float res = count/m;
    if(res == int(res)){
        printf("%d",res);
    }else{
        printf("%d/%d",int(count),m);
    }
    return 0;
}

posted on 2015-12-23 10:13  泽口靖子  阅读(161)  评论(0)    收藏  举报

导航