百炼OJ - 1001 - Exponentiation
题目链接
哇一遍AC的感觉也太爽了吧:)
#include <stdio.h>
#include <string.h>
int times=0;
char *myCalc(char source[1000], char s[1000], int times)
{
if( times == 0 ) return s;
int last=0,a=strlen(source),b=strlen(s);
char res[1000]={0};
for(int i=0;i<(a+b-1);i++) // times
{
int temp=last,first,end;
if( i < a )
{
first = 0;
end = i+1;
}
else if( i < b )
{
first = 0;
end = a;
}
else
{
first = i-b+1;
end = a;
}
for(int j=first;j<end;j++)
{
temp += (source[j]-'0')*(s[i-j]-'0');
}
res[i] = temp%10 + '0';
last = temp/10;
}
if( last != 0 ) res[a+b-1] = last+'0';
//puts(res);
return myCalc(source,res,times-1);
}
int main()
{
char input[10];
while( scanf("%s %d",input,×) != EOF )
{
int num=0,points = 0,flag = 0;
char sum[1000] = {0};
for(int i=strlen(input)-1;i>=0;i--)
{
if(input[i] == '0' && flag == 0)continue;
else if(flag == 0) flag = 1;
if(input[i] == '.')
{
flag = 2;
continue;
}
sum[num++] = input[i];
if(flag == 1) points ++;
}
if( flag != 2 ) points = 0;
for(int i=strlen(sum)-1;i>=0;i--)
{
if(sum[i] == '0')
sum[i] = 0;
else break;
}
//printf("%d %s\n",points,sum);
char *results = myCalc(sum,sum,times-1);
if( strlen(results) < points*times )
{
printf(".");
for(int i=0;i<(points*times-strlen(results));i++)
printf("0");
}
for(int i=strlen(results)-1;i>=0;i--)
{
if( (i+1) == points*times )
printf(".");
printf("%c",results[i]);
}
printf("\n");
}
return 0;
}
百炼OJ - 1001 - Exponentiation的更多相关文章
- POJ 1001 Exponentiation(大数运算)
POJ 1001 Exponentiation 时限:500 ms 内存限制:10000 K 提交材料共计: 179923 接受: 43369 描述:求得数R( 0.0 < R < ...
- 百炼1001: Exponentiation 解题
链接:http://bailian.openjudge.cn/practice/1001/ 思路 乍一看是很简单的题目,但是答案必须高精度输出,因此需要手动实现一个高精度运算方法.如果直接使用int, ...
- [POJ 1001] Exponentiation C++解题报告 JAVA解题报告
Exponentiation Time Limit: 500MS Memory Limit: 10000K Total Submissions: 126980 Accepted: 30 ...
- [POJ] #1001# Exponentiation : 大数乘法
一. 题目 Exponentiation Time Limit: 500MS Memory Limit: 10000K Total Submissions: 156373 Accepted: ...
- POJ 1001 Exponentiation 无限大数的指数乘法 题解
POJ做的非常好,本题就是要求一个无限位大的指数乘法结果. 要求基础:无限大数位相乘 额外要求:处理特殊情况的能力 -- 关键是考这个能力了. 所以本题的用例特别重要,再聪明的人也会疏忽某些用例的. ...
- poj 1001 Exponentiation 第一题 高精度 乘方 难度:1(非java)
Exponentiation Time Limit: 500MS Memory Limit: 10000K Total Submissions: 138526 Accepted: 33859 ...
- 九度oj 1001 A+B for Matrices 2011年浙江大学计算机及软件工程研究生机试真题
题目1001:A+B for Matrices 时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:15235 解决:6172 题目描述: This time, you are supposed ...
- 九度OJ 1001:A+B for Matrices
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:17682 解决:7079 题目描述: This time, you are supposed to find A+B where A and ...
- 北大OJ 1001题
题目:输入一序列的正实数和幂次(正整数)对,然后打印结果(具体的比这个精细) 这道题是关于大数计算的(大数求幂),从开始建立思路,到写代码.调式到最后被AC以及最终的优化,总共用了差不多一天的时间.开 ...
随机推荐
- mysql 视图、触发器、事务、存储过程、函数
一 视图 视图是一个虚拟表(非真实存在),其本质是[根据SQL语句获取动态的数据集,并为其命名],用户使用时只需使用[名称]即可获取结果集,可以将该结果集当做表来使用. 使用视图我们可以把查询过程中的 ...
- .NetCore学习笔记:二、基于Dapper的泛型Repository
为减少代码量,这里实现一个基于Dapper的泛型Repository. 这里需要引用Dapper.dll和Dapper.Contrib.dll. 接口定义: /// <summary> / ...
- 2_abstractions
2. Up and down the level of abstraction In this chapter, we'll travel up and down the level of abstr ...
- Linux运维---16. Kolla部署OpenStack外接rabbit集群
# 前提时rabbit集群已经搭建完成 vim /etc/kolla/globals.yml enable_rabbitmq: "no" rpc_transport_url: &q ...
- 154.Ajax处理csrf防御
在普通的form表单中采用post请求提交数据,可以在form表单的method=post的form标签下面,添加一个csrf_token标签{% csrf_token %},或者是直接手动的添加一个 ...
- C# asp.net 配置文件连接sql 数据库
先引用 using System.Configuration;//配置文件using System.Data.SqlClient; 我这里使用的是SqlServer 2008 sa 用户 密码也为s ...
- centos7下自动备份mysql数据库
环境:centos7 .mysql5.7 第一步:创建自动备份脚本文件 mkdir backup cd backup touch backup.sh 第二步:在备份脚本文件中写入备份脚本 vim ba ...
- C语言sprintf函数的深入理解
由于sprintf跟printf在用法上几乎一样,只是打印的目的地不同而已,前者打印到字符串中,后者则直接在命令行上输出.这也导致sprintf比printf有用得多.所以本文着重介绍sprintf, ...
- 爬虫 urllib
内置http请求库 模块 urllib.request 请求模块 urllib.error 异常处理模块 urllib.parse url解析模块 urllib.robotparser ...
- 洛谷P1086 花生采摘
https://www.luogu.org/problem/P1086 #include <bits/stdc++.h> using namespace std; typedef long ...