ZOJ 1205 Martian Addition
来源:互联网 发布:淘宝截止2016 编辑:程序博客网 时间:2024/09/21 09:18
简单的大数加法
#include <stdio.h>#include <string>#include <algorithm>#include <iostream>using namespace std;int convertCharToInt(char c){ if (c >= '0' && c <= '9') { return c - '0'; } else if (c >= 'a' && c <= 'j') { return (c - 'a') + 10; } else { return 0; }}char convertIntToChar(int n){ if (n >= 0 && n <= 9) { return '0' + n; } else if (n >= 10 && n <= 19) { return 'a' + (n - 10); } else { return '0'; }}int main(){ string n1, n2; while (getline(cin, n1) && getline(cin, n2)) { reverse(n1.begin(), n1.end()); reverse(n2.begin(), n2.end()); int l1 = n1.length(); int l2 = n2.length(); string result; int temp = 0; for (int i = 0; i < l1 || i < l2; i++) { int i1 = 0; int i2 = 0; if (i < l1) { i1 = convertCharToInt(n1[i]); } if (i < l2) { i2 = convertCharToInt(n2[i]); } int s = temp + i1 + i2; result += convertIntToChar(s % 20); temp = s / 20; } if (temp > 0) { result += convertIntToChar(temp); } reverse(result.begin(), result.end()); printf("%s\n", result.c_str()); } return 0;}
- ZOJ 1205 Martian Addition
- zoj 1205 Martian Addition
- zoj 1205 Martian Addition
- ZOJ 1205 Martian Addition
- ZOJ 1205 Martian Addition
- ZOJ 1205 Martian Addition
- zoj 1205 Martian Addition
- ZOJ 1205 Martian Addition
- ZOJ 1205: Martian Addition
- ZOJ 1205 Martian Addition
- zoj 1205 Martian Addition
- Solution of ZOJ 1205 Martian Addition
- ZOJ Problem Set - 1205 Martian Addition
- zoj 1205.Martian Addition
- ZOJ 1205 Martian Addition (20进制加法)
- Martian Addition
- fjnu 1865 Martian Addition
- 【ACM】Martian Addition
- Android权限大全
- 使用PHP处理POST上传时$_FILES数组为何为空
- 字符串反转
- 手机界面设计中9种常用的布局
- asp.net mvc源码分析-Action篇 IModelBinder
- ZOJ 1205 Martian Addition
- redis配置详解
- Configure ubuntu apache to forward the request to tomcat app
- google浏览器调试javascript
- GBK WINDOWS-936
- java中的getResourceAsStream()
- 征服 Redis
- 命令式至函數式隨記(六)
- setsockopt()用法(参数详细说明)