跳到正文

剪贴板

剪贴板 agriv0wq

原文
剪贴板信息

剪贴板信息

收录
更新
口算题生成器\large\boxed{口算题生成器}
C++
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include<ctime>
using namespace std;
int i,fhx,fhy,n,fh,x3,y4,x4,tag[10001],ex[10001],ey[10001],y3;
float x,y,ans[10001],xx,yy;
int gcd(int x,int y){
	return (y==0?x:gcd(y,x%y));
}
void wh(int i){
	if (i%3==0) putchar(10);
}
void emptys(int f){
	for (int i=f+1;i<=25;i++) printf(" ");
}
int WS(int x){
	int ans=0;
	while (x!=0) ans++,x/=10;
	return ans;
}
int main(){
	srand(time(0));
	printf("请输入题数:");
	freopen("口算.txt","w",stdout);
	scanf("%d",&n);
	for (i=1;i<=n;i++){
		int s=0;
		fh=rand()%4;
		if (fh==0) {
			fhx=rand()%2;
			fhy=rand()%2;
			x=1.0*(rand()%10000)/100;
			if (fhx) x=-x;
			y=1.0*(rand()%10000)/100;
			if (fhy) y=-y;
			if (x<0) printf("(%.2f)",x),s+=(x>-10.0?7:8);
			else printf("%.2f",x),s+=(x<10.0?4:5);
			printf("-"),s++;
			if (y<0) printf("(%.2f)",y),s+=(y>-10.0?7:8);
			else printf("%.2f",y),s+=(y<10.0?4:5);
			printf("="),s++;
			emptys(s);ans[i]=x-y;
		}
		else if (fh==1){
			fhx=rand()%2;
			fhy=rand()%2;
			x=1.0*(rand()%10000)/100;
			if (fhx) x=-x;
			y=1.0*(rand()%10000)/100;
			if (fhy) y=-y;
			if (x<0) printf("(%.2f)",x),s+=(x>-10.0?7:8);
			else printf("%.2f",x),s+=(x<10.0?4:5);
			printf("+"),s++;
			if (y<0) printf("(%.2f)",y),s+=(y>-10.0?7:8);
			else printf("%.2f",y),s+=(y<10.0?4:5);
			printf("="),s++;
			emptys(s);ans[i]=x+y;
		}
		else  if (fh==2){
			fhx=rand()%2;
			fhy=rand()%2;
			x=1.0*(rand()%100)/10;
			if (fhx) x=-x;
			y=1.0*(rand()%100)/10;
			if (fhy) y=-y;
			if (x<0) printf("(%.1f)",x),s+=6;
			else printf("%.1f",x),s+=3;
			printf("×"),s+=2;
			if (y<0) printf("(%.1f)",y),s+=6;
			else printf("%.1f",y),s+=3;
			printf("="),s++;
			emptys(s);ans[i]=x*y;
		}
		else{
			x=1.0*(rand()%100)/10;
			y=1.0*(rand()%100)/10;
			if (y==0.0){
				i--;
				continue;
			}
			xx=x;yy=y;
			while (yy!=(int)(yy)||xx!=(int)(xx)) xx=xx*10,yy=yy*10;
			y3=(int)(yy);y4=(int)(yy);x4=(int)(xx);
			while (y3>1){
				if (y3%2==0) y3/=2;
				else if (y3%5==0) y3/=5;
				else break;
			}
			if (y3!=1&&x4%y4!=0){
				printf("%.1f",x);
				printf("/");
				printf("%.1f",y);
				printf("=");
				emptys(8);
				tag[i]=1;
				ex[i]=x4/gcd(x4,y4);
				ey[i]=y4/gcd(x4,y4);
			}
			else{
				i--;
				continue;
			}
		}
		wh(i);
	}
	fclose(stdout);
	freopen("答案.txt","w",stdout);
	for (i=1;i<=n;wh(i),i++)
		if (tag[i]==1) emptys(WS(ex[i])+WS(ey[i])+1),printf("%d/%d",ex[i],ey[i]);
		else printf("%25.2f",ans[i]);
	fclose(stdout);
	return 0;
}