求调
  • 板块学术版
  • 楼主tjx123456
  • 当前回复0
  • 已保存回复0
  • 发布时间2024/11/27 22:01
  • 上次更新2024/11/28 10:07:06
查看原帖
求调
1180981
tjx123456楼主2024/11/27 22:01

题目传送门

code

#include <cstdio>
const int INF=0x3f3f3f;
const int maxn=1000005;
int remainder[maxn],integer[maxn];
int c[maxn],cc[maxn]; 
int main(){
	//input
	int n,d;
	scanf("%d%d",&n,&d);
	
	//do
	if(n%d==0){
		printf("%d.0\n",n/d);
	}else{
		int t=n/d;
		printf("%d.",t);
		
		int count=0;
		while(t){
			t/=10;
			count++;
		}
		if(n/d==0) count++;
		
		int x=2;
		remainder[1]=n%d;
		int l=-INF,r=-INF;
		
		for(;x<=INF;x++){
			integer[x]=remainder[x-1]*10/d;
			remainder[x]=remainder[x-1]*10%d;
			
			if(!remainder[x]) break;
			if(c[remainder[x]]){
				if(cc[c[remainder[x]]]==integer[x]){
					l=c[remainder[x]];
					r=x-1;
					break;
				}
			}
			
			c[remainder[x]]=x;
			cc[c[remainder[x]]]=integer[x];
		}
		
		//output
		int s=count+1;
		for(int i=2;i<x;i++){
			if(i==l){
				printf("(");
				s++;
			}
			
			if(s==76){
				puts("");
				s=0;
			}
			
			printf("%d",integer[i]);
			s++;
			
			if(s==76){
				puts("");
				s=0;
			}
			
			if(i==r){
				printf(")");
				s++;
			}
			
			if(s==76){
				puts("");
				s=0;
			}
		}
	}
	return 0;
}

78pts

dalao求调

2024/11/27 22:01
加载中...