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

#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:51
加载中...