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又对数字的列产生了兴趣:现 ...
随机推荐
- “jni.h”: No such file or directory
VS2010解决方案: 进入 “包含目录“ 方式: 右键项目属性页-> 配置属性->VC++目录->包含目录 在”包含目录“中编辑 添加以下路径: C:\Program Files\ ...
- [转载]Oracle基础知识
一.oracle安装过程略 二.sys用户和system用户 (1)sys用户是超级用户,具有最高权限,具有sysdba角色,有create database的权限 默认密码是change_onins ...
- 转:探讨android更新UI的几种方法
本文转自:http://www.cnblogs.com/wenjiang/p/3180324.html 作为IT新手,总以为只要有时间,有精力,什么东西都能做出来.这种念头我也有过,但很快就熄灭了,因 ...
- Apache Virtual Include
2.目录支持includes: <Directory /> Options None //不支持includes ...
- 使用JsPlumb绘制拓扑图的通用方法
转自:http://www.it165.net/pro/html/201311/7616.html 使用JsPlumb绘制拓扑图的通用方法 一. 实现目标 绘制拓扑图, 实际上是个数据结构和算法的问题 ...
- [Linux]命令root与other切换
切换至root:sudo -i切换至other:su 用户名
- Python Standard Library 学习(一) -- Built-in Functions 内建函数
内建函数列表 Built-in Functions abs() divmod() input() open() staticmethod() all() enumerate() int() ord() ...
- iOS: 学习笔记, swift扩展
// // YYExtension.swift // // Created by yao_yu on 14-7-18. // Copyright (c) 2014年 yao_yu. All right ...
- 控制反转(IoC)与依赖注入(DI)
1.控制反转(Inversion of Control)与依赖注入(Dependency Injection) 控制反转即IoC (Inversion of Control),它把传统上由程序代码直接 ...
- Encoding 类别
Encoding 類別 .NET Framework 4.5 表示字元編碼方式. 繼承階層架構 System.Object System.Text.Encoding System.Tex ...