fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. int main(int argc, char **argv) {
  6. static char line[80];
  7.  
  8. while (fgets(line, 80, stdin)) {
  9. char *p = strtok(line, " ");
  10.  
  11. if (p) {
  12. if (strcmp(p, "F") == 0) {
  13. unsigned long n = 0;
  14. p = strtok(NULL, " \r\n");
  15. p += strlen(p);
  16.  
  17. unsigned long a = 1, b = 1, c;
  18. while (*--p) {
  19. if (*p == '1') n += b;
  20.  
  21. // a,b = a+b,a
  22. c = a+b;
  23. b = a;
  24. a = c;
  25. }
  26.  
  27. printf("%lu\n", n);
  28.  
  29. } else {
  30. unsigned long n = strtoul(strtok(NULL, " "), NULL, atoi(p));
  31.  
  32. unsigned long a = 1, b = 1, c;
  33.  
  34. while (a <= n) {
  35. c = a+b;
  36. b = a;
  37. a = c;
  38. }
  39.  
  40. while (b > 0) {
  41. if (b <= n) {
  42. printf("1");
  43. n -= b;
  44. } else {
  45. printf("0");
  46. }
  47.  
  48. c = a-b;
  49. a = b;
  50. b = c;
  51. }
  52.  
  53. printf("\n");
  54. }
  55. }
  56. }
  57.  
  58. return 0;
  59. }
Success #stdin #stdout 0s 2172KB
stdin
10 16
10 32
10 9024720
F 10
F 1
F 111111
F 100000
F 10110110100111001
stdout
1001000
10101000
1010100101010100000010001000010010
1
1
20
8
2868