Skip to content

软件:期中考试问题总结 #27

Description

@ghostbody

软件学院15级教务1班程序设计(实验)期中考试参考答案

1000

#include <stdio.h>

int main() {
  int n;
  int plus;
  int min;
  int flag = 1;

  scanf("%d", &n);

  int i, j, k;
  plus = n / 2;
  min = 0;

  for(i = 0; i < n; i++) {    
    for(j = 0; j < min; j++) {
      printf("-");
    }
    for(j = 0; j < plus; j++) {
      printf("+");
    }
    printf("+");
    for(j = 0; j < plus; j++) {
      printf("+");
    }
    for(j = 0; j < min; j++) {
      printf("-");
    }
    printf("\n");
    if(flag) {
      plus --;
      min ++;
    } else {
      plus++;
      min--;
    }

    if(plus <= 0) {
      flag = 0;
    }
  }

  return 0;
}

1001

#include <stdio.h>

const int chair = 30;
const int trees = 10;

int main() {
  int i;
  int height;
  int apple[10];
  int ans = 0;

  for(i = 0; i < trees; i++) {
    scanf("%d", &apple[i]);
  }
  scanf("%d", &height);
  for(i = 0; i < trees; i++) {
    if(height + chair >= apple[i]) {
      ans ++;
    }
  }

  printf("%d\n", ans);

  return 0;
}

1002

#include <stdio.h>

int main() {
  int m,n;
  int i;
  unsigned long long ans;
  scanf("%d", &m);

  while(m--) {
    scanf("%d", &n);
    ans = 1;
    for(i = 2; i <= n; i++) {
      ans += i*i*i;
    }
    printf("%lld\n", ans);
  }

  return 0;
}

1003

#include <stdio.h>

int main() {
  int n;
  int array[101];
  int i, j;
  int ans;

  while(scanf("%d", &n) && n) {
    ans  = 0;
    for(i = 0; i < n; i++) {
      scanf("%d", &array[i]);
    }

    for(i = 0; i < n; i++) {
      for(j = 0; j < n; j++) {
    if(array[j] * 2 == array[i]) {
      ans++;
    }
      }
    }
    printf("%d\n", ans);
  }

}

1004

#include<stdio.h>

int main(){
  int i,j,a[1000][1000];
  int n;
  while(scanf("%d", &n) && n) {
    for(i = 0; i < n; i++) {
      for(j = 0; j < n; j++){
    a[i][0] = 1;
    a[i][i] = 1;
      }
    }
    for(i = 2; i < n; i++) {
      for(j = 1; j <= i-1; j++) {
    a[i][j] = a[i-1][j-1] + a[i-1][j];
      }
    }
    for(i = 0; i < n; i++){
      for(j = 0; j <= i; j++) {
    printf("%d\t", a[i][j]);
      }
      printf("\n");
    }
  }
  return 0;
}

1005

#include <stdio.h>

int main() {
  int start_hour;
  int start_min;
  int end_hour;
  int end_min;

  int sleep_hour;
  int sleep_min;

  scanf("%d:%d", &start_hour, &start_min);
  scanf("%d:%d", &end_hour, &end_min);

  if((end_hour < start_hour) ||
     ((end_hour == start_hour) && (start_min > end_min))) {
    end_hour += 24;
  }

  sleep_hour = end_hour - start_hour;
  sleep_min = end_min - start_min;

  if(sleep_min < 0) {
    sleep_min += 60;
    sleep_hour--;
  }

  if(sleep_hour < 10){
    printf("0");
  }
  printf("%d:", sleep_hour);

  if(sleep_min < 10) {
    printf("0");
  }
  printf("%d\n", sleep_min);

  return 0;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions