题目链接: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. html-----003

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  2. Win32中GDI+应用(二)--初始化与清理

    GDI+提供了GdiplusStartup和 GdiplusShutdown 函数来进行初始化和完成清理工作.你必须在调用其他的GDI+函数之前,调用GdiplusStartup函数,在完成GDI+工 ...

  3. mysql5.7.14安装与配置

    参考文章链接: http://jingyan.baidu.com/article/afd8f4de9006d934e286e9fd.html http://www.cnblogs.com/wenthi ...

  4. compser 执行命令提示do not run composer as root/super !

    这个是因为composer为了防止非法脚本在root下执行,解决办法随便切换到非root用户即可

  5. phpcms安装完成后总是跳转到install/install.php

       很多人在本地安装phpcms后总是跳转到install/install.php.由于很多人是第一次使用phpcms,不知道为何会出现这个错误.出现这个大都是phpcms的缓存所致. 如何解决ph ...

  6. (三大框架SSH)面试题锦集

    http://www.cnblogs.com/dieyf/p/4109233.html

  7. INI解析模块的C++实现

    INI文件格式是某些平台或软件上的配置文件的非正式标准,以节(section)和键(key)构成,常用于微软Windows操作系统中. 节(section) 节用方括号括起来,单独占一行,例如: [s ...

  8. 4d tensor

    偶然在一个ppt中看到了如下关于tensor的解释,清晰明白,所以post在这里,以备后续查看 根据这个理解: theano中的input(4d tensor):[mini-batch size, n ...

  9. 百度编辑器ueditor 使用

    ueditor 百度开源的一个 编辑器 ,支持api.扩展,demo丰富.推荐下 以前写 编辑 词典的使用 jquery-te  轻量级编辑器..当时看中了 它代码轻巧.容易改. 把他的功能改了好多. ...

  10. bzoj 1040: [ZJOI2008]骑士 環套樹DP

    1040: [ZJOI2008]骑士 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 1755  Solved: 690[Submit][Status] ...