1189: Integer Inquiry

本文介绍了一种处理大数求和的算法实现方案,该方案能够有效地解决超过标准整型变量长度的大数求和问题。通过对输入的大数进行逐位处理,并利用数组存储中间结果的方式,最终实现了对多个大数的累加操作。

1189: Integer Inquiry


StatusIn/OutTIME LimitMEMORY LimitSubmit TimesSolved UsersJUDGE TYPE
stdin/stdout1s8192K879320Standard
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. ``I only wish Timothy were here to see these results.'' (Chip moved to a new apartment, once one became available on the third floor of the Lemon Sky apartments on Third Street.)

 

Input

The input will consist of at most 100 lines of text, each of which contains a single VeryLongInteger. Each VeryLongInteger will be 100 or fewer characters in length, and will only contain digits (no VeryLongInteger will be negative).

 

The final input line will contain a single zero on a line by itself.

 

Output

Your program should output the sum of the VeryLongIntegers given in the input.

 

Sample Input

123456789012345678901234567890
123456789012345678901234567890
123456789012345678901234567890
0

Sample Output

370370367037037036703703703670
#include<stdio.h>
#include<string.h>
int main()
{
    char s[400];
    int i,j,l;
    int a[400]={0},b[400]={0};
    while(scanf("%s",s)==1)
    {
        if(strcmp(s,"0")==0) break;
        int len=strlen(s);
        l=399;
        for(i=len-1;i>=0;i--)
        {
            b[l--]=s[i]-'0';
        }
        for(i=399;i>=0;i--)
        {
            a[i]+=b[i];
        }
    }
    for(i=399;i>=0;i--)
    {
        if(a[i]>=10)
        {
            a[i-1]+=a[i]/10;
            a[i]%=10;
        }
    }
    int flag=0;
    for(i=0;i<400;i++)
    {
        if(flag||i==399||a[i])
        {
            printf("%d",a[i]);
            flag=1;
        }
    }
    printf("/n");
    return 0;
}
### SQL语句存在的问题 1. **日期格式问题**:在 SQL 中,日期值需要用单引号括起来,原语句 `update_time = 2025-09-01` 会被解析为数学运算(2025 减去 9 再减去 1),而不是日期值。正确的写法应该是 `update_time = '2025-09-01'`。 2. **数字作为更新值问题**:`updater = 1` 若 `updater` 是字符串类型,也需要用单引号括起来;若为数字类型则无需引号。这里假设 `updater` 为字符串类型,应写成 `updater = '1'`。 ### 优化后的 SQL 语句 以下是优化后的 SQL 语句示例: ```java import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Update; @Mapper public interface LogisticsInquiryMapper { @Update("UPDATE logistics_inquiry SET inquiry_status = #{status}, update_time = '2025-09-01', updater = '1' WHERE id = #{id}") int updateInquiryStatus(Long id, String status); } ``` 在上述代码中,`updateInquiryStatus` 方法用于更新 `logistics_inquiry` 表中指定 `id` 记录的 `inquiry_status`、`update_time` 和 `updater` 字段。注意,`update_time` 使用单引号括起来表示日期值,`updater` 假设为字符串类型也用单引号括起来。 ### 进一步优化建议 1. **动态日期**:实际应用中,`update_time` 通常使用当前时间。可以使用数据库的函数来获取当前时间,例如 MySQL 中使用 `NOW()` 函数: ```java @Update("UPDATE logistics_inquiry SET inquiry_status = #{status}, update_time = NOW(), updater = '1' WHERE id = #{id}") int updateInquiryStatus(Long id, String status); ``` 2. **参数化 `updater`**:将 `updater` 作为参数传递,增加代码的灵活性: ```java @Update("UPDATE logistics_inquiry SET inquiry_status = #{status}, update_time = NOW(), updater = #{updater} WHERE id = #{id}") int updateInquiryStatus(Long id, String status, String updater); ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值