HDU-3787(字符串模拟)
现在请计算A+B的结果,并以正常形式输出。
1,234 2,345,678
2346912
思路:
#include <iostream>
#include <string>
#include <cmath>
#include <cstdio>
using namespace std; int main()
{
string num1,num2;
while(cin>>num1>>num2)
{
//判断正负号
int flag1 = ,flag2 = ;
if(num1[] == '-') flag1 = -;
if(num2[] == '-') flag2 = -;
//判断两数字的长度
int len1=,len2=;
for(int i = ;i < num1.length();i++)
if(num1[i]>=''&&num1[i]<='') len1++;
for(int i = ;i < num2.length();i++)
if(num2[i]>=''&&num2[i]<='') len2++;
//分别求出两个数的绝对值
__int64 number1=,number2=;
for(int i = ;i < num1.length();i++) {
if(num1[i]>=''&&num1[i]<='') {
number1 += (num1[i]-'')*pow(,--len1);
}
}
for(int i = ;i < num2.length();i++) {
if(num2[i]>=''&&num2[i]<='') {
number2 += (num2[i]-'')*pow(,--len2);
}
}
number1 *= flag1;
number2 *= flag2;
printf("%I64d\n",number1+number2);
}
return ;
}
HDU-3787(字符串模拟)的更多相关文章
- 用字符串模拟两个大数相加——java实现
问题: 大数相加不能直接使用基本的int类型,因为int可以表示的整数有限,不能满足大数的要求.可以使用字符串来表示大数,模拟大数相加的过程. 思路: 1.反转两个字符串,便于从低位到高位相加和最高位 ...
- HDU-1002.大数相加(字符串模拟)
本题大意:给出两个1000位以内的大数a 和b,让你计算a + b的值. 本题思路:字符串模拟就能过,会Java的大佬应该不会点进来...... 参考代码: #include <cstdio&g ...
- Codeforces Round #425 (Div. 2) B. Petya and Exam(字符串模拟 水)
题目链接:http://codeforces.com/contest/832/problem/B B. Petya and Exam time limit per test 2 seconds mem ...
- HDU-Digital Roots(思维+大数字符串模拟)
The digital root of a positive integer is found by summing the digits of the integer. If the resulti ...
- Vigenère密码 2012年NOIP全国联赛提高组(字符串模拟)
P1079 Vigenère 密码 题目描述 16 世纪法国外交家 Blaise de Vigenère 设计了一种多表密码加密算法――Vigenère 密 码.Vigenère 密码的加密解密算法简 ...
- 单词数 HDU 2072 字符串输入控制
单词数 HDU 2072 字符串输入控制 题意 lily的好朋友xiaoou333最近很空,他想了一件没有什么意义的事情,就是统计一篇文章里不同单词的总数.下面你的任务是帮助xiaoou333解决这个 ...
- CCF(JSON查询:40分):字符串+模拟
JSON查询 201709-3 纯字符串模拟,考的就是耐心和细心.可惜这两样我都缺... #include<iostream> #include<cstdio> #includ ...
- HDU 1753 大明A+B(字符串模拟,简单题)
简单题,但要考虑一些细节: 前导0不要,后导0不要,小数长度不一样时,有进位时,逆置处理输出 然后处理起来就比较麻烦了. 题目链接 我的代码纯模拟,把小数点前后分开来处理,写的很繁杂,纯当纪念——可怜 ...
- HDU 4119Isabella's Message2011成都现场赛I题(字符串模拟)
Isabella's Message Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
随机推荐
- Linux 高可用(HA)集群之keepalived详解
http://freeloda.blog.51cto.com/2033581/1280962 大纲 一.前言 二.Keepalived 详解 三.环境准备 四.LVS+Keepalived 实现高可用 ...
- Android开发/源代码资源汇总
全网最全的Android游戏源代码汇总 mod=viewthread&tid=5080&fromuid=5" target="_blank">htt ...
- Apache配置HTTPS协议搭载SSl配置全过程
1.首先要开启相应的扩展和辅助的dll(ssleay32.dll,libeay32.dll)到system32下 2.生成服务器证书 安装好在bin目录下有一个openssl.exe文件,用来生成证书 ...
- C++ int转string
一.使用atoi 说明: itoa( int value, char *string, int radix ); 第一个参数:你要转化的int; 第 ...
- 【转载】python:特殊函数使用方式
[转载]廖雪峰的官方网站 可变参数 在Python函数中,还可以定义可变参数.顾名思义,可变参数就是传入的参数个数是可变的. 我们以数学题为例子,给定一组数字a,b,c……,请计算a2 + b2 + ...
- C++ STL set集合容器
汇总了一些set的常用语句,部分参考了这篇:http://blog.163.com/jackie_howe/blog/static/199491347201231691525484/ #include ...
- java集合框架03
Collections工具类的使用 public class News implements Comparable { private int id; //新闻编号 private String ti ...
- hdu 1175
#include <iostream> #include <string> #include <stdio.h> using namespace std; int ...
- Mysql group_concat
select p.id,p.parent_id,group_concat(distinct(CONCAT("分类名称:",c.name)) order by c.id desc s ...
- MySQL数据库备份与恢复方法(转)
来源于:http://www.jb51.net/article/25686.htm 网站数据对我们对站长来说都是最宝贵的,我们平时应该养成良好的备份数据的习惯. 常有新手问我该怎么备份数据库, ...