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 dalang0407 at 2010-06-01 09:36:02 on Problem 2109
#include <iostream>
#include <cmath>
using namespace std;

//double result[1000];

int main()
{
	double n, p, k, temp;
	int i, counter = 0;
	double* result;
	while(cin >> n >> p)
	{
		result = new double;
		k = 2;
		temp = pow(k, n);
		while(temp < p)
		{
			k++;
			temp = pow(k, n);
		}
		if (temp == p)
		{
			result[counter++] = k;

		}
		else if (temp > p)
		{
			result[counter++] = k - 1;
		}
		

	}
	i = 0;
	while(i < counter)
	{
		printf("%.0lf\n", result[i++]);
	}
	return 0;
}

为啥只有最后一个结果是对的??
而如果我用静态数组 就对了 
是不是我动态数组哪写错了??

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