题目1003:A+B(按逗号分隔的A+B)

时间:2021-10-15 16:17:57

题目链接:http://ac.jobdu.com/problem.php?pid=1003

详解链接:https://github.com/zpfbuaa/JobduInCPlusPlus

参考代码:

//
// 1003 A+B.cpp
// Jobdu
//
// Created by PengFei_Zheng on 2017/4/14.
// Copyright © 2017年 PengFei_Zheng. All rights reserved.
// #include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <cmath> using namespace std; char a[],b[];
int num1,num2; int main(){
while(scanf("%s%s",a,b)!=EOF){
int lena = (int)strlen(a);
int lenb = (int)strlen(b);
num1 = num2 = ;
int size1 = ;
int size2 = ;
bool flag1 = (a[]>=''&&a[]<='') ? true : false;
bool flag2 = (b[]>=''&&b[]<='')? true : false;
for(int i = lena - ; i >= ; i--){
if(a[i]>='' && a[i]<=''){
num1+=(a[i]-'')*pow(,size1);
size1++;
}
}
for(int i = lenb - ; i >= ; i--){
if(b[i]>='' && b[i]<=''){
num2+=(b[i]-'')*pow(,size2);
size2++;
}
}
if(flag1&&flag2) printf("%d\n",num1+num2);
else if(flag1 && !flag2) printf("%d\n",num1-num2);
else if(flag2 && !flag1) printf("%d\n",num2-num1);
else if(!flag1 && !flag2) printf("%d\n",-num1-num2);
}
}
/**************************************************************
Problem: 1003
User: zpfbuaa
Language: C++
Result: Accepted
Time:0 ms
Memory:1608 kb
****************************************************************/