Golden October online programming Competition No. 1: Little Girl count

Source: Internet
Author: User

The output format is completely output according to the question requirements. After running, an error is prompted. The error cause is unknown. Paste the code first and then debug-=


Q & A description:

Input example:

1

10

1000000000

Output example:

1

2

2



#include <stdio.h>#include <stdlib.h>typedef long long FINGER;FINGER getReturn(){char buffer[12];char temp = 0;for(int i = 0;i < 10;i++){temp = getchar();if(temp == '\n'){return atoi(buffer);}buffer[i] = temp;}return 0;}typedef struct _FINGERRECORD{      FINGER data;      struct _FINGERRECORD *next;} FINGERRECORD; int where(FINGER input){if(input >= 1 && input <= 5){return input;}else{int row, line;row = (input - 5) / 4;line = (input - 5) % 4;if(row % 2 == 0){return (5 - line);}else{return (1 + line);}}}void disp(FINGERRECORD *link){link = link->next;    for(int i = 0; link != NULL; i++){        printf("%d\n",where(link->data));        link = link->next;    }}int main(){ FINGER f = 0;    FINGERRECORD *head, *current, *tail;    current = tail = (FINGERRECORD*)malloc(sizeof(FINGERRECORD));    head = NULL;    for(int i = 1;; i++){        if(i == 1){            head = current;        }else{            tail->next = current;        }        tail = current;         current = (FINGERRECORD*)malloc(sizeof(FINGERRECORD));        FINGER ff = getReturn();        if(ff == 0){        break;        }else{        current->data = ff;        }    }    tail->next = NULL;    disp(head);   return 0;}

UPDATE: The ninth line of the Code has a range bug. After modification, an error is still reported-=


So we only keep the core code ......

#include <iostream>typedef long long FINGER;int where(FINGER input){if(input >= 1 && input <= 5){return input;}else{int row, line;row = (input - 5) / 4;line = (input - 5) % 4;if(row % 2 == 0){return (5 - line);}else{return (1 + line);}}}int main(){ FINGER  temp;while(1){std::cin >> temp;std::cout << where(temp) << std::endl;}   return 0;}

Result:


Sure enough, the question requirement is inconsistent with the standard answer, and the question is pitted again-=

Golden October online programming Competition No. 1: Little Girl count

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.