uva 424 Integer Inquiry

#include<iostream>
#include<cctype>
#include<cstdlib>
#include<cstring>
using namespace std;

int main(){
    char a[110][110];
    int result[110];
    int num = 0,index;
    memset(a,‘a‘,sizeof(a));        //没有初始化,wa 了好几次
    memset(result,0,sizeof(result));
    string s;
    while(cin >> s){
        if(s[0] == ‘0‘)
            break;
        index = 0;
        for(int i = s.length() - 1; i >= 0; i--)  //将读入的字符串反转,低位在前
            a[num][index++] = s[i];
        num++;
    }
    int c = 0;
    for(int i = 0; i < 110; i++){
        int sum = 0;
        for(int j = 0; j < num; j++){
            if(isdigit(a[j][i]))
                sum += a[j][i] - ‘0‘;
        }
        sum += c;
        c = sum / 10;
        result[i] = sum % 10;
    }
    int k;
    for(k = 109; result[k] == 0; k--);           //忽略前导0
    for(;k>=0;k--)
        cout << result[k];
    cout << endl;
    return 0;
}
时间: 2024-10-10 20:03:07

uva 424 Integer Inquiry的相关文章

UVa 424 Integer Inquiry 【大数相加】

解题思路:因为给定的数据是多组,所以我们只需要多次做加法就可以了,将上一次的和又作为下一次加法运算的一个加数. 反思:还是题意理解不够清楚,最开始以为只是算三个大数相加,后来才发现是多个,然后注意到当输入a的第一个字符为0的时候结束运算,输出结果.  Integer Inquiry  One of the firstusers of BIT's new supercomputer was Chip Diller. He extended his explorationof powers of 3

424 - Integer Inquiry

 Integer Inquiry  One of the first users of BIT's new supercomputer was Chip Diller. He extended his exploration of powers of 3 to go from 0 to 333 and he explored taking various sums of those numbers. ``This supercomputer is great,'' remarked Chip.

Integer Inquiry UVA 424

#include <stdio.h> #include <string.h> #define MAXN 100+5 #define MAXL 100+5 char addend[MAXN][MAXL];//保存加数 char ans[MAXL];//保存结果 int len[MAXN];//保存每个加数的长度 int main(){ int cnt=0;//加数的个数 int max=0;//最长的加数的长度 int i,k,j=MAXL-1,sum,carry; //freope

hdu1047 Integer Inquiry

/* Integer Inquiry Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 15874 Accepted Submission(s): 4079 Problem Description One of the first users of BIT's new supercomputer was Chip Diller. He exte

hdu acm-1047 Integer Inquiry(大数相加)

Integer Inquiry Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 11678    Accepted Submission(s): 2936 Problem Description One of the first users of BIT's new supercomputer was Chip Diller. He ex

POJ 1053 Integer Inquiry (大数加法,还是Java大法好)

Integer Inquiry Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 32674   Accepted: 12789 Description One of the first users of BIT's new supercomputer was Chip Diller. He extended his exploration of powers of 3 to go from 0 to 333 and he

HDOJ 1047 Integer Inquiry

JAVA睑板.... Integer Inquiry Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 12042    Accepted Submission(s): 3037 Problem Description One of the first users of BIT's new supercomputer was Chip D

POJ 1503 Integer Inquiry(大数相加,java)

题目 我要开始练习一些java的简单编程了^v^ import java.io.*; import java.util.*; import java.math.*; public class Main { /** * @param args */ public static void main(String[] args) throws Exception { // 定义并打开输入文件 Scanner cin = new Scanner(System.in); BigInteger a, sum

POJ 1053 Integer Inquiry &amp;&amp; HDOJ 1047 Integer Inquiry (大数加法)

题目链接(POJ):http://poj.org/problem?id=1503 题目链接(HDOJ):http://acm.hdu.edu.cn/showproblem.php?pid=1047 Integer Inquiry Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 30856   Accepted: 12007 Description One of the first users of BIT's new su