HDU 1230 火星A+B
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1230
水题模拟一道,主要考验代码能力,刷完题就感觉自己还是太弱了。
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
char a[],b[];
int L,now,prime[],A[],B[];
bool f[];
void init()
{
int k,N=,j=;
memset(f,false,sizeof(f));
for(int i=;N<=&&i<=;i++)
{
// cout<<i<<' '<<f[i]<<endl;
if(f[i]==false)
{
prime[N]=i;
N=N+;
for(j=i+i;j<=;j=j+i){ f[j]=true; }
}
else
continue;
}
/* for(int i=1;i<=25;i++)
cout<<prime[i]<<' ';
cout<<endl; */
return;
}
void atoA(int x)
{
L++;
int num=;
for(;a[now]!=','&&a[now]!='\0';now++)
{
num=num*+a[now]-'';
}
if(a[now++]!='\0')
atoA(x+);
A[L-x]=num;
return;
}
void btoB(int x)
{
L++;
int num=;
for(;b[now]!=','&&b[now]!='\0';now++)
{
num=num*+b[now]-'';
}
if(b[now++]!='\0')
btoB(x+);
B[L-x]=num;
return;
}
int main()
{
init();
int i,l,ans[];
while(scanf("%s %s",a,b))
{
if(strcmp(a,"")==||strcmp(b,"")==)
break;
memset(A,,sizeof(A));
memset(B,,sizeof(B));
now=;L=;
atoA();
l=L;
now=;L=;
btoB();
if(l<L)
l=L;
int J=;
for(i=;i<=l;i++)
{
ans[i]=A[i]+B[i]+J;
J=ans[i]/prime[i];
ans[i]%=prime[i];
}
while(J)
{
l++;
ans[l]=J%prime[l];
J=J/prime[l];
}
bool first=true;
for(i=l;i>;i--)
{
if(first)
{
first=false;
printf("%d",ans[i]);
}
else
printf(",%d",ans[i]);
}
cout<<endl;
}
return ;
}
HDU 1230 火星A+B的更多相关文章
- 题解报告:hdu 1230 火星A+B(字符串)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1230 Problem Description 读入两个不超过25位的火星正整数A和B,计算A+B.需要 ...
- 【HDOJ】1230 火星A+B
个人觉得这道题没那么水,wa了几次,才发现自己居然没有给srcb数组reset,打错了.搞死啊. #include <stdio.h> #include <string.h> ...
- HDU 1230饭前开胃菜
题意不讲了.. 没思路,上去就是干.... 两个所谓要加的数直接存到数组,开一个标记的数组,然后直接加,乱搞一波,就好了. 细心一点. #include<iostream> #includ ...
- hdu 1075 What Are You Talking About 火星文翻译成英文
What Are You Talking About Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 102400/204800 K ...
- 转载:hdu 题目分类 (侵删)
转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012. ...
- HDU——PKU题目分类
HDU 模拟题, 枚举1002 1004 1013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 1037 1039 1042 1047 1048 ...
- HDU 1713 最小公倍数与最大公约数的问题 相遇周期
欢迎参加——BestCoder周年纪念赛(高质量题目+多重奖励) 相遇周期 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/ ...
- hdu 4003 Find Metal Mineral 树形DP
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4003 Humans have discovered a kind of new metal miner ...
- hdu 1716(dfs)
题目链接 : http://acm.hdu.edu.cn/showproblem.php?pid=1716 排列2 Problem Description Ray又对数字的列产生了兴趣:现 ...
随机推荐
- 完全步卸载oracle11g步骤
完全 步 卸载oracle11g骤: . 开始->设置->控制面板->管理工具->服务 停止所有Oracle服务. . 开始->程序->Oracle - OraH ...
- CSS Positioning(定位)
Positioning(定位) CSS定位属性允许你为一个元素定位.它也可以将一个元素放在另一个元素后面,并指定一个元素的内容太大时,应该发生什么. 元素可以使用的顶部,底部,左侧和右侧属性定位.然而 ...
- ios专题 - CocoaPods - 安装
职业走得很累,停下来,温故技术.顺便开始我得ios博客文章. [原创]http://www.cnblogs.com/luoguoqiang1985 安装 第一步:执行以下命令 sudo gem ins ...
- 使用Ubuntu 新建vpn过程
1.更新软件源 sudo apt-get update 2.安装pip sudo apt-get install python-pip 3.安装shadowsocks s ...
- HDU_1241 Oil Deposits(DFS深搜)
Problem Description The GeoSurvComp geologic survey company is responsible for detecting underground ...
- 用3种方法在 operator= 中处理“自我赋值”
假设你建立一个class 用来保存一个指针指向一块动态分配的位图. class Bitmap {......}; class Widget{ ... private: Bitmap* pb ; }; ...
- 网页解析Jsoup简单使用
public static void main(String[] args) throws IOException { //System.out.println("Hello World!& ...
- 【PHP】 foreach循环中变量引用的一道面试题
$a = array('a','b','c'); foreach($a as &$v){} foreach($a as $v){ } var_dump($a); 现在.不要打开浏览器,猜测一下 ...
- JVM学习笔记-运行时数据区
不同于C,C++程序,Java程序的内存管理工作由Java虚拟机(JVM)接管,这减低了java程序员的负担,但如果出现内存泄露与溢出问题如报OutOfMemory,StackOverFlow异常错误 ...
- Ninject 自动注册
首先这个问题我纠结了很久,看到autofac强大的自动注册功能,我感觉Ninject弱爆了,不过Ninject自带属性注册,感觉很方便,所以还在纠结Ninject 传统的绑定方式 public cla ...