sicily 1020. Big Integer

这道题的关键也就两句话

    for (int i = 0; i < len; ++i)
    {
        ans = (ans*10 + x[i]-‘0‘) % num;
    }

其余也没什么好说的

#include <stdio.h>
#include <string.h>

int getVeryLongNumberMod(char x[],int num){
    int len = strlen(x);
    int ans = 0;
    for (int i = 0; i < len; ++i)
    {
        ans = (ans*10 + x[i]-‘0‘) % num;
    }
    return ans;
}

int main(int argc, char const *argv[])
{
    int size,NumberSize;
    int BaseNumber[400];
    char Total[401] ;
    scanf("%d",&size);
    while (size--) {
        scanf("%d",&NumberSize);
        for (int i = 0; i<NumberSize; i++) {
            scanf("%d",&BaseNumber[i]);
        }
        scanf("%s",Total);
        printf("(");
        for (int i = 0; i<NumberSize; i++) {
            if ( i != NumberSize - 1 ){
                printf("%d,",getVeryLongNumberMod(Total, BaseNumber[i]));
            }else
                printf("%d)\n",getVeryLongNumberMod(Total, BaseNumber[i]));
        }
    }

}
				
时间: 2024-08-13 15:39:21

sicily 1020. Big Integer的相关文章

SOJ 1020 Big Integer

题目大意: 输入T,表示测试样例总数.对每个样例,首先输入n(n ≤ 10),接下来有n个数输入,计作b1...bn,最后输入x,其中x是一个非常大不超过400字符的长正整数. 限制条件:1 < bi ≤ 1000,  1 ≤ i ≤ n 且 gcd(bi, bj) = 1 ,  (1 ≤ i, j ≤ n, i ≠ j) 让M = b1 * b2 * ... * bn , x < M 输出:x % bi  = ri 格式: (r1,r2,...,rn) 解题思路: 由于长正整数x非常大,不能

编程题目分类(剪辑)

1. 编程入门 2. 数据结构 3. 字符串 4. 排序 5. 图遍历 6. 图算法 7. 搜索:剪枝,启发式搜索 8. 动态规划/递推 9. 分治/递归 10. 贪心 11. 模拟 12. 算术与代数 13. 组合问题 14. 数论 15. 网格,几何,计算几何 [编程入门] PC 110101, uva 100, The 3n+1 problem, 难度 1 PC 110102, uva 10189, Minesweeper, 难度 1 PC 110103, uva 10137, The T

Sicily1020-大数求余算法及优化

Github最终优化代码: https://github.com/laiy/Datastructure-Algorithm/blob/master/sicily/1020.c 题目如下: 1020. Big Integer Constraints Time Limit: 1 secs, Memory Limit: 32 MB Description Long long ago, there was a super computer that could deal with VeryLongInt

.Net Core CLR FileFormat Call Method( Include MetaData, Stream, #~)

.Net Core  CLR PE 文件启动方法,找到函数入口点,调用整个.Net 程式宿主. 使用方法:可以利用Visual Studio新建一个控制台应用程序,然后生成DLL,替换掉本程序DLL,新建C++ .CPP 文件 然后即可运行看到效果. 整个代码情况如下 包括 IMIAGE_CORE20_HEADER MetaData, 表格对其方式等待 4 #include "pch.h" 5 #include <iostream> 6 #include <Windo

杭电1020

Encoding Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 26063    Accepted Submission(s): 11467 Problem Description Given a string containing only 'A' - 'Z', we could encode it using the follow

HDU字符串基础题(1020,1039,1062,1088,1161,1200,2017)

并不是很精简,随便改改A过了就没有再简化了. 1020. Problem Description Given a string containing only 'A' - 'Z', we could encode it using the following method: 1. Each sub-string containing k same characters should be encoded to "kX" where "X" is the only c

sicily 1063. Who&#39;s the Boss

Time Limit: 1sec    Memory Limit:32MB Description Several surveys indicate that the taller you are, the higher you can climb the corporate ladder. At TALL Enterprises Inc. this "de facto standard" has been properly formalized: your boss is alway

sicily 1051. Biker&#39;s Trip Odomete

DescriptionMost bicycle speedometers work by using a Hall Effect sensor fastened to the front fork of the bicycle. A magnet is attached to one of the spokes on the front wheel so that it will line up with the Hall Effect switch once per revolution of

PAT 1020. Tree Traversals (25)

1020. Tree Traversals (25) Suppose that all the keys in a binary tree are distinct positive integers. Given the postorder and inorder traversal sequences, you are supposed to output the level order traversal sequence of the corresponding binary tree.