RE求助
  • 板块学术版
  • 楼主yuukoyuuko
  • 当前回复0
  • 已保存回复0
  • 发布时间2024/10/9 15:53
  • 上次更新2024/10/9 19:00:36
查看原帖
RE求助
1101906
yuukoyuuko楼主2024/10/9 15:53

#include <stdio.h>  
#include <stdlib.h>  
  
typedef struct node  
{   int         data;  
    struct node * next;  
} NODE;  
  
void output( NODE *, int );  
void change( int, int, NODE * );  
  
void output( NODE * head, int kk )  
{   int k=0;  
  
    printf("0.");  
    while ( head->next != NULL && k<kk )  
    {   printf("%d", head->next->data );  
        head = head->next;  
        k ++;  
    }  
    printf("\n");  
}  
  
int main()  
{   int n, m,k;  
    NODE * head;  
  
    scanf("%d%d%d", &n, &m, &k);  
    head = (NODE *)malloc( sizeof(NODE) );  
    head->next = NULL;  
    head->data = -1;  
    change( n, m, head );  
    output( head,k );  
    return 0;  
}  

void change(int a, int b, NODE* c){
    NODE* current = c;
    int* remainder = (int*)malloc(b * sizeof(int));
    for(int i = 0; i < b; i++){
        remainder[i] = -1;
    }
    while(a != 0 && remainder[a] == -1){
        remainder[a] = current->data;
        a *= 10;
        NODE* newnode = (NODE*)malloc(sizeof(NODE));
        newnode->next = NULL;
        newnode->data = a/b;
        current->next = newnode;
        current = newnode;
        a = a % b;
    }
    if(a != 0){
        NODE* start = c;
        while(start->data != remainder[a]){
            start = start->next;
        }
        current->next = start->next;
    }
    free(remainder);
}

求助大佬,为什么会有一个用例RE,看了半天没看出来?

2024/10/9 15:53
加载中...