“Sometimes it is the people no one can imagine anything of who do the things no one can imagine.” ― Sir Alan Turing


ADS

ADS

Saturday, April 8, 2017

UVa 11150 Cola Solution in C / C++


Source Code

#include<stdio.h>

int main() {
  int n, i, r, p, b, tb;
  while (scanf("%d", & n) == 1) {
    tb = 0;
    if (n % 3 == 2)
      p = n + 1;
    else
      p = n;
    for (i = p; i >= 3; i = b + r) {
      b = i / 3;
      r = i % 3;
      tb = tb + b;
    }
    if (n % 6 == 0)
      n = n + 1;
    if ((n + 2) % 6 == 0)
      n = n + 1;
    printf("%d\n", n + tb);
  }
  return 0;
}

No comments:

Post a Comment