sicily_1052 Candy Sharing Game

标签(空格分隔): sicily

题目链接: http://soj.sysu.edu.cn/1052

代码

早期的代码用了goto, 结构不是很好。

// Problem#: 1052
#include

int main() {
  int i, k = 0, n;
  int arr[1000], b[1000];
A: scanf("%d", &n);
  if (!n) return 0;
  for (i = 1; i <= n; i++) {
    scanf("%d", &arr[i]);
  }
  arr[0] = arr[n];

C: for (i = 1; i <= n; i++) {
  if (arr[i - 1] != arr[i]) {
    k++;
    goto B;
  }
}
   goto D;

B:for (i = 1; i <= n; i++) {
   b[i] = (arr[i - 1] + 1) / 2 + (arr[i] + 1) / 2;
}
  b[0] = b[n];
  for (i = 0; i <= n; i++) {
    if (b[i] % 2) b[i]++;
    arr[i] = b[i];
  }
  goto C;

D: printf("%d %d\n", k, arr[n]);
  k = 0;
  goto A;
}

你可能感兴趣的:(sicily_1052 Candy Sharing Game)