标签:style blog http color io os ar for sp
输出格式完全按照题目要求输出,运行后提示结果出错。出错原因未知。先贴上代码以后再DEBUG-=
输入样例:
1
10
1000000000
输出样例:
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; }
更新:发现代码第九行有个范围BUG,修改之后依然报错-=
于是只保留核心代码……
#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; }
果然题目要求与标准答案不一致,又被坑了一次-=
标签:style blog http color io os ar for sp
原文地址:http://blog.csdn.net/firedom/article/details/40316373