[sicily online]1020. Big Integer
来源:互联网 发布:淘宝仓库宝贝在哪里 编辑:程序博客网 时间:2024/05/11 04:56
Constraints
Time Limit: 1 secs, Memory Limit: 32 MB
Description
Long long ago, there was a super computer that could deal with VeryLongIntegers(no VeryLongInteger will be negative). Do you know how this computer stores the VeryLongIntegers? This computer has a set of n positive integers: b1,b2,...,bn, which is called a basis for the computer.
The basis satisfies two properties:
1) 1 < bi <= 1000 (1 <= i <= n),
2) gcd(bi,bj) = 1 (1 <= i,j <= n, i ≠ j).
Let M = b1*b2*...*bn
Given an integer x, which is nonegative and less than M, the ordered n-tuples (x mod b1, x mod b2, ..., x mod bn), which is called the representation of x, will be put into the computer.
Input
The input consists of T test cases. The number of test cases (T) is given in the first line of the input.
Each test case contains three lines.
The first line contains an integer n(<=100).
The second line contains n integers: b1,b2,...,bn, which is the basis of the computer.
The third line contains a single VeryLongInteger x.
Each VeryLongInteger will be 400 or fewer characters in length, and will only contain digits (no VeryLongInteger will be negative).
Output
For each test case, print exactly one line -- the representation of x.
The output format is:(r1,r2,...,rn)
Sample Input
232 3 51042 3 5 713
Sample Output
(0,1,0)(1,1,3,6)
题目分析:
第一次做时,本来想做个字符串模拟整型数据的加、减、乘、除、模运算,用了自己的库,所以把题目中的大整数和除数都用string来表示,然后用自己写的string取模,最后总是超时,看了别的大神的做法,原来除数没必要用string表示(因为小于1000),这样就不会超时了
#include<iostream>#include<stdio.h>#include<cmath>#include<iomanip>#include <vector>#include <string>#include <algorithm>#include <sstream>using namespace std;string strMod(string x1,int x2){int num=0;for(string::size_type i=0;i<x1.size();i++){num=num*10+(x1[i]-'0');num=num%x2;}//直接把int转化成stringstringstream strStream;strStream<<num;string result=strStream.str();return result;}int main(){int n;cin>>n;for(int i=0;i<n;i++){int m;scanf("%d",&m);vector<int> data;int tmpStr;for(int j=0;j<m;j++){cin>>tmpStr;data.push_back(tmpStr);}//end forstring bigInteger;cin>>bigInteger;cout<<"(";for (int j=0;j<m-1;j++){string tmp=strMod(bigInteger,data[j]);printf("%s,",tmp.c_str());}string tmp=strMod(bigInteger,data[m-1]);printf("%s)\n",tmp.c_str());}}
- [sicily online]1020. Big Integer
- Sicily.1020. Big Integer
- Sicily 1020. Big Integer
- sicily 1020. Big Integer
- Sicily 1020. Big Integer
- sicily 1020.Big Integer
- Sicily 1020. Big Integer
- [sicily]1020. Big Integer
- sicily 1020. Big Integer
- [sicily] 1020. Big Integer
- Sicily 1020 Big Integer
- sicily 1020 Big Integer
- Sicily 1020 Big Integer
- sicily 1020 Big Integer
- sicily 1020 Big Integer
- Sicily 1020. Big Integer | 大整数取模运算
- Sicily 1020 Big Integer(高精度运算)
- 1020. Big Integer
- Smarty模板技术
- STL Algorithms 之 copy
- 设计一个简易的处理器(1)--定义指令集体系结构(ISA)
- JS数组元素去重
- Openfire用户密码加密方法
- [sicily online]1020. Big Integer
- KiB、MiB与KB、MB的区别
- ios tableCell 中同时获取点击的位置和所在的indexPath
- VoIP通信控制系统的小知识
- 书
- RGB 常用颜色对照表
- OpenGL中混色的用法
- 单元测试的关键难题——内部输入
- JS的Trim