题目链接: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的更多相关文章

  1. 题解报告:hdu 1230 火星A+B(字符串)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1230 Problem Description 读入两个不超过25位的火星正整数A和B,计算A+B.需要 ...

  2. 【HDOJ】1230 火星A+B

    个人觉得这道题没那么水,wa了几次,才发现自己居然没有给srcb数组reset,打错了.搞死啊. #include <stdio.h> #include <string.h> ...

  3. HDU 1230饭前开胃菜

    题意不讲了.. 没思路,上去就是干.... 两个所谓要加的数直接存到数组,开一个标记的数组,然后直接加,乱搞一波,就好了. 细心一点. #include<iostream> #includ ...

  4. hdu 1075 What Are You Talking About 火星文翻译成英文

    What Are You Talking About Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 102400/204800 K ...

  5. 转载:hdu 题目分类 (侵删)

    转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012. ...

  6. HDU——PKU题目分类

    HDU 模拟题, 枚举1002 1004 1013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 1037 1039 1042 1047 1048 ...

  7. HDU 1713 最小公倍数与最大公约数的问题 相遇周期

    欢迎参加——BestCoder周年纪念赛(高质量题目+多重奖励) 相遇周期 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/ ...

  8. hdu 4003 Find Metal Mineral 树形DP

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4003 Humans have discovered a kind of new metal miner ...

  9. hdu 1716(dfs)

    题目链接 : http://acm.hdu.edu.cn/showproblem.php?pid=1716     排列2   Problem Description Ray又对数字的列产生了兴趣:现 ...

随机推荐

  1. JS禁止横竖屏切换,强制横竖屏显示

    js判断屏幕横竖屏: function orient() { //alert('gete'); if (window.orientation == 0 || window.orientation == ...

  2. iOS: 学习笔记实例, 用代码控制视图创建与切换

    1. 创建iOS, Single View Application.2. 修改YYViewController.m // // YYViewController.m // DynamicViewDem ...

  3. css的继承、层叠和特殊性

    1,继承  css的某些样式是具有继承性的,那么什么是继承呢?继承是一种规则,它允许样式不仅应用于某个特定html标签元素,而且应用于其后代. 但注意有一些css样式是不具有继承性的.如border: ...

  4. NorFlash

    一.NorFlash概述 1.NorFlash Intel于1988年首先开发出NOR Flash 技术,彻底改变了原先由EPROM(Erasable Programmable Read-Only-M ...

  5. 【POJ3208】 (DP)

    Apocalypse Someday Description The number 666 is considered to be the occult “number of the beast” a ...

  6. 【POJ1082】Calendar Game (博弈)

    [题目] Description Adam and Eve enter this year's ACM International Collegiate Programming Contest. La ...

  7. request.getParameter() 、 request.getInputStream()和request.getReader() 使用体会

    request.getParameter(). request.getInputStream().request.getReader()这三种方法是有冲突的,因为流只能被读一次.比如:当form表单内 ...

  8. LeetCode解题报告:Reorder List

    Reorder List Given a singly linked list L: L0→L1→…→Ln-1→Ln,reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→… Yo ...

  9. c++ 名字粉碎(name mangling)

    转自Ibm: Name mangling is the encoding of function and variable names into unique names so that linker ...

  10. Linux Shell编程(23)——文本处理命令

    处理文本和文本文件的命令sort文件排序, 通常用在管道中当过滤器来使用. 这个命令可以依据指定的关键字或指定的字符位置, 对文件行进行排序. 使用 -m 选项, 它将会合并预排序的输入文件. 想了解 ...