Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

测试数据没问题,但提交显示编译错误,实在不会改了,求大神指点

Posted by 3212052051243 at 2022-12-05 11:42:30 on Problem 1001
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<math.h>
#include<string.h>
char num[1000];
int T; /*指数*/
int answ[100];
int L; /*小数位数*/
int take(int a[100]) /*将数存入数组*/
{
	int flag;
	flag = 0;     /*用于判断底数是否为零*/
	int i;           /*小数点位置*/
	for (i = 0; num[i] != '.'; i++)
	{
		continue;
	}
	int k;           /*首零结束部位*/
	for (k = 0; num[k] == '0'; k++)
	{
		continue;
	}
	int j;          /*尾零结束位置*/
	j = strlen(num) - 1;
	if(j>i)   /*在该条件下输入数字不仅存在整数,还有小数部分,若不是则仅为整数,整数的尾同样需要存入数组*/
	for (; num[j] == '0'; j--)
	{
		continue;
	}
	L = j - i;/*求出小数位数*/
	if (L < 0)
		L = 0;
	int l;
	l = 0;
	for(;j>=k;j--)
	{ 
		if ('0' <= num[j] <= '9')
			if (num[j] != '.')
			{
				a[l++] = num[j] - 48;
				flag = 1;
			}
	}
	if (flag == 0)
	{
		a[0] = 0;
		printf("%d", a[0]);
		return 0;
	}
	else if (a[0] == 1 && L == 0)
	{
		printf("%d", a[0]);
		return 0;
	}
	return 1;
}
void data(int a[100],int b[100])    /*复制底数*/
{
	int i;
	for (i = 0; i <= 100; i++)
		b[i] = a[i];
}
void multy(int a[1000],int b[1000])    /*模拟计算乘法*/
{
	int i;
	int j;
	for (i = 0;i<100;i++)
	{
		for (j = 0; j < 100; j++)
		{
			answ[i + j] += a[i] * b[j];
			answ[i + j + 1] += answ[i + j] / 10;
			answ[i + j] = answ[i + j] % 10;
		}
	}
	for (i = 0; i < 100; i++)
		a[i] = answ[i];
	memset(answ, 0, sizeof(answ));
}
int main()
{
	int a[1000] = {0};
	int b[1000] = {0};
	int t;
	while(scanf("%s%d",&num,&T)!=EOF)
	{
		t=take(a);
		if (t)/*判断底数是否为零或一,若是则直接输出,不是则进入指数判断*/
		{
			data(a, b);
			if (T >= 1)/*指数不为零的情况,需要进行计算,否则直接输出1*/
			{
				L = L * T;/*经过计算后的小数位数,当小数数位为零时不必输出小数点*/
				while (--T)
					multy(a, b);
				int j;
				for (j = 999; a[j] == 0; j--)  /*找到数字开始位置*/
				{
					if (j == L-1)  /*当数组下表与小数点位数相同则说明仅含小数部分可以停止查找剩下的全为需要输出部分*/
						break;
					continue;
				}
				if (j != L-1)   /*整数与小数都有的数字*/
				{
					for (; j >= 0; j--)
					{
						printf("%d", a[j]);
						if (j == L&&L!=0)/* 当L为零的时候,数字仅为整数*/
							printf(".");

					}
				}
				else   /* 只含有小数部分*/
				{
					printf(".");
					for (; j >= 0; j--)
					{
						printf("%d", a[j]);

					}
				}
			}
			else     /*指数为零且底数不为零直接输出1*/
				printf("1");
		}
		printf("\n");
		memset(a, 0, sizeof(a));
		memset(b, 0, sizeof(b));
	}
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator