提交记录 #533
提交时间:2025-01-05 20:02:52
语言:c
状态:Unaccepted
编译情况:编译成功
固定测试点#1:
固定测试点#2:
固定测试点#3:
固定测试点#4:
附加测试点暂不可用
H25【选做▪中学】求循环节
void change(int n,int m,NODE* head){
int shang,yu,check[200000],k=0,i,flag=0;
n*=10;
NODE* p;
NODE* p_pre=head;
p=(NODE*)malloc(sizeof(NODE));
shang=n/m;
yu=n%m;
if (yu==0){
p->data=-1;
p->next=NULL;
p_pre->next=p;
// printf("enter\n");
return;
}
check[k++]=yu;
p->data=shang;
p->next=NULL;
p_pre->next=p;
p_pre=p;
while (1){
yu*=10;
shang=yu/m;
yu=yu%m;
if (yu==0){
p->data=-1;
p->next=NULL;
p_pre->next=p;
p_pre=p;
p_pre->next=NULL;
// printf("enter\n");
return;
}
check[k++]=yu;
p=(NODE*)malloc(sizeof(NODE));
p->data=shang;
p->next=NULL;
p_pre->next=p;
p_pre=p;
for (i=0;i<k-1;i++){
if (yu==check[i]){
flag=1;
}
}
if (flag) break;
}
}
NODE* find(NODE* head,int* n){
NODE* p=head;
NODE* q=head->next;
NODE* new_head;
int count=1;
while (p->next!=NULL){
p=p->next;
// if (p->next==NULL) printf("够啦!\n");
// printf("%d\n",p->data);
}
if (p->data==-1){
new_head=NULL;
*n=0;
return new_head;
}
while (q->data!=p->data){
q=q->next;
}
new_head=q;
while (q->next!=p){
q=q->next;
count++;
}
q->next=new_head;
*n=count;
return new_head;
}