金色十月线上编程比赛第一题:小女孩数数

输出格式完全按照题目要求输出,运行后提示结果出错。出错原因未知。先贴上代码以后再DEBUG-=


答题说明:

输入样例:

1

10

1000000000

输出样例:

1

2

2


bogon:desktop firedom$ ./testtt 

1

10

1000000000


1

2

2

bogon:desktop firedom$ 





#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;
}

结果:


果然题目要求与标准答案不一致,又被坑了一次-=

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值