PKU_1001_Exponentiation

部署运行你感兴趣的模型镜像
Exponentiation

Description

Problems involving the computation of exact values of very large magnitude and precision are common. For example, the computation of the national debt is a taxing experience for many computer systems.
This problem requires that you write a program to compute the exact value of Rn where R is a real number ( 0.0 < R < 99.999 ) and n is an integer such that 0 < n <= 25.

Input

The input will consist of a set of pairs of values for R and n. The R value will occupy columns 1 through 6, and the n value will be in columns 8 and 9.

Output

The output will consist of one line for each line of input giving the exact value of R^n. Leading zeros should be suppressed in the output. Insignificant trailing zeros must not be printed. Don't print the decimal point if the result is an integer.

Sample Input

95.123 12
0.4321 20
5.1234 15
6.7592  9
98.999 10
1.0100 12


Sample Output

548815620517731830194541.899025343415715973535967221869852721
.00000005148554641076956121994511276767154838481760200726351203835429763013462401
43992025569.928573701266488041146654993318703707511666295476720493953024
29448126.764121021618164430206909037173276672
90429072743629540498.107596019456651774561044010001
1.126825030131969720661201


Source Code

/**************************
   对乘号进行重载,使其可以进行高精度浮点数的乘法
***************************/
string operator* (string s1,string s2)
{
	int l1=s1.length(),l2=s2.length();
	int i,j,k=0,pos1=0,pos2=0;
	string result="";

	int a[200],b[200],c[200];
	for (i=0;i<200;i++)
	{
		a[i]=0;
		b[i]=0;
		c[i]=0;
	}
	
	//把string类转化为数组类,去掉小数点,并记录小数点位置
	for (i=0;i<l1;i++)
	{	
		if (s1[l1-1-i]=='.')
		{
			k=1;
			pos1=i;
		}
		else
		{
			a[i-k]=s1[l1-1-i]-'0';
		}
	}
	k=0;
	for (i=0;i<l2;i++)
	{	
		if (s2[l2-1-i]=='.')
		{
			k=1;
			pos2=i;
		}
		else
		{
			b[i-k]=s2[l2-1-i]-'0';
		}
	}
	
	//计算结果,并存储于数组C中。
       for (i=0;i<l1-(pos1!=0);i++)
		for (j=0;j<l2-(pos2!=0);j++)
		{
			c[i+j]+=a[i]*b[j];
		}

	for (i=0;i<=l1+l2-2;i++)
	{
		c[i+1]+=c[i]/10;
		c[i]=c[i]%10;
	}
	
	//把数组类重新转化为string类
	k=(pos1!=0)+(pos2!=0);     //判断原string类是否有小数点
	int l=l1+l2-k;             //根据小数点的个数,确定最终答案的位数
	for (i=0;i<l;i++)
	{
		result+=c[l-1-i]+'0';
	}


        //添加小数点
	int pos=l-pos1-pos2;
	if (pos<l)
		result.insert(pos,1,'.');
	return result;
}

/**************************
   采用二分法进行幂的计算
***************************/
string power(string s,int n)
{
	if (n==1) 
		return s;
	else 
	{
		string subResult= power(s,n/2);	
		subResult=subResult * subResult;
		if (n%2==1)
		{
			subResult = subResult * s;
		}
		return subResult;
	}
}


/**************************
   去掉多余的零并进行输出
***************************/
void outPrint(string s)
{
	int end=0,beg=s.length()-1;
	while (s[beg]=='0'||s[beg]==0) beg--;
	if (s[beg]=='.') beg--;
	while (s[end]=='0'||s[end]==0) end++;
	int i;
	for (i=end;i<=beg;i++)
		cout<<s[i];
	cout<<endl;
}

int main()
{
	string s;
	int n;
	while (cin>>s>>n)
	{
		string result=power(s,n);
		outPrint(result);
	}
	return 0;
}

参考链接: http://blog.youkuaiyun.com/fanxing1/article/details/5730978

您可能感兴趣的与本文相关的镜像

Stable-Diffusion-3.5

Stable-Diffusion-3.5

图片生成
Stable-Diffusion

Stable Diffusion 3.5 (SD 3.5) 是由 Stability AI 推出的新一代文本到图像生成模型,相比 3.0 版本,它提升了图像质量、运行速度和硬件效率

### 关于 PKU_Campus 数据库文件格式及其用途 在 IT 领域中,`pku_campus.db` 文件通常是一个 SQLite 数据库文件。SQLite 是一种轻量级的关系型数据库管理系统,广泛用于嵌入式应用和小型项目中[^4]。以下是关于 `pku_campus.db` 的可能格式和用途: #### 1. **文件格式** SQLite 数据库文件的标准扩展名为 `.db` 或 `.sqlite`。这种文件本质上是以二进制形式存储的数据表集合,支持 SQL 查询语言。可以通过以下命令查看其结构: ```bash sqlite3 pku_campus.db ``` 运行上述命令后,可以执行如下操作来了解数据表的内容: ```sql .tables -- 查看所有表格名称 .schema table_name -- 查看特定表格的定义 SELECT * FROM table_name LIMIT 10; -- 浏览前几条记录 ``` #### 2. **潜在用途** 根据命名惯例,“PKU Campus” 可能指北京大学校园相关的某个系统或应用程序。因此,该数据库文件可能是为了管理与校园活动、学生信息或其他资源有关的数据而设计的。 - 如果涉及学生活动,则可能会有类似于 `students`, `events`, 和 `registrations` 这样的表格。 - 若是科研领域中的工具包组件之一,则需进一步确认具体上下文环境下的功能定位[^5]。 另外值得注意的是,在某些情况下,此类数据库也可能被用来保存地理空间信息(GIS),特别是当它关联到地图服务或者位置追踪类软件时[^6]。 #### 示例代码展示如何连接并查询此类型的 SQLite 数据库 下面提供了一个简单的 Python 脚本例子,演示怎样加载以及读取一个 SQLite 数据库内的基本信息: ```python import sqlite3 conn = sqlite3.connect('pku_campus.db') cursor = conn.cursor() # 获取所有的表名 cursor.execute("SELECT name FROM sqlite_master WHERE type='table';") tables = cursor.fetchall() print(f"Tables found: {tables}") for table in tables: tableName = table[0] print(f"\nData from Table '{tableName}': ") try: cursor.execute(f'SELECT * FROM "{tableName}" LIMIT 5') rows = cursor.fetchall() for row in rows: print(row) except Exception as e: print(e) conn.close() ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值