题目链接:http://poj.org/problem?id=2305

ime Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 5326   Accepted: 2267

Description

Given a base b and two non-negative base b integers p and m, compute p mod m and print the result as a base b integer. p mod m is defined as the smallest non-negative integer k such that p = a*m + k for some integer a.

Input

Input consists of a number of cases. Each case is represented by a line containing three unsigned integers. The first, b, is a decimal number between 2 and 10. The second, p, contains up to 1000 digits between 0 and b-1. The third, m, contains up to 9 digits between 0 and b-1. The last case is followed by a line containing 0.

Output

For each test case, print a line giving p mod m as a base-b integer.

Sample Input

2 1100 101
10 123456789123456789123456789 1000
0

Sample Output

10
789
 #include<stdio.h>
#include<iostream>
#include<cstring>
#include<limits.h>
#include<queue>
using namespace std;
char a[],b[];
long long c,e;//开int会WA
int len1,len2;
int f[];
int change1()//把b转换成十进制//对的
{
int d=,i;
for(i=;i<len2;i++)
{
d=d*c+b[i]-'';
}
return d;
}
void change2()//把十进制e转化成目标进制输出
{
int i;
for(i=;i<;i++)
{
if(e<c)break;
f[i]=e%c;
e/=c;
}
f[i]=e;
int len3=i+;
for(i=len3-;i>=;i--)
{
if(i==len3-&&f[i]==&&len3!=)
continue;
else
cout<<f[i];
}
cout<<endl;
}
int main()
{
int i;
while(cin>>c&&c)
{
cin>>a>>b;
len1=strlen(a);
len2=strlen(b);
int d=change1();
//cout<<d<<endl;
e=;
for(i=;i<len1;i++)
{
e=e*c+a[i]-'';
e=e%d;
}
//cout<<e<<endl;
change2();
}
return ;
}

POJ 2305 Basic remains(进制转换)的更多相关文章

  1. POJ 2305:Basic remains 进制转换

    Basic remains Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5221   Accepted: 2203 Des ...

  2. poj2305-Basic remains(进制转换 + 大整数取模)

    进制转换 + 大整数取模一,题意: 在b进制下,求p%m,再装换成b进制输出. 其中p为b进制大数1000位以内,m为b进制数9位以内二,思路: 1,以字符串的形式输入p,m; 2,转换:字符串-&g ...

  3. poj 2305(指定进制,大数取模)

    题意:输入一个进制b,在输入两个基于b进制的大整数 x,y ,求x%y的b进制结果. http://162.105.81.212/JudgeOnline/problem?id=2305 函数: Str ...

  4. POJ 1220 大数字的进制转换,偷下懒,用java

    题意为进制转换,Java的大数类就像是作弊 import java.math.BigInteger; import java.util.Scanner; public class Main { pub ...

  5. poj1220 (高精度任意进制转换)

    http://poj.org/problem?id=1220 高精度任意进制转换 代码是从discuss里找到的,据说是maigo神牛写的. 超精简!! 我自己第一写的时候,还把n进制先转成10进制, ...

  6. SQL Server 进制转换函数

    一.背景 前段时间群里的朋友问了一个问题:“在查询时增加一个递增序列,如:0x00000001,即每一个都是36进位(0—9,A--Z),0x0000000Z后面将是0x00000010,生成一个像下 ...

  7. [No000071]C# 进制转换(二进制、十六进制、十进制互转)

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  8. JS中的进制转换以及作用

    js的进制转换, 分为2进制,8进制,10进制,16进制之间的相互转换, 我们直接利用 对象.toString()即可实现: //10进制转为16进制 ().toString() // =>&q ...

  9. 结合stack数据结构,实现不同进制转换的算法

    #!/usr/bin/env python # -*- coding: utf-8 -*- # learn <<Problem Solving with Algorithms and Da ...

随机推荐

  1. PHP5.6通过CURL上传图片@符无效的兼容问题

    今天本来想试试一个图片云的API,于是本地做了个上传图片的测试,结果灰常郁闷的发现以前一直用的好好的CURL上传图片居然死活不起作用,本来几分钟搞定的事情,结果折腾了大半天才终于找到原因,居然是兼容性 ...

  2. C++ unordered_map 在key为string类型和char*类型时测试时间性能差异

    测试系统liunx centos6.5 代码如下 #include <string.h> #include <sstream> #include <list> #i ...

  3. 【转】Oracle + PHP Cookbook(php oracle clob 长度超过4000如何写入)

      在甲骨文LOB和PHP工作 由哈里Fuecks 达到4,000字节的限制?输入LOB ... 在这个"Oracle + PHP Cookbook"HowTo中,您将学习可用的L ...

  4. C语言:SQLITE3的学习

    Sqlite基础学习 一.sqlite的概念 SQLite是一款轻型数据库,是遵守ACID的关系型数据库管理系统,由C语言开发设计.Sqlite的设计目标着眼于嵌入式领域,所以具有占用系统资源低和处理 ...

  5. FZU 2089 数字游戏

    Problem 2089 数字游戏  Problem Description 现在,给你2个整形数字A和B.你的任务就是计算出A+B的结果C后,统计C中数字5出现的次数.  Input 输入数据第一行 ...

  6. linux 下查看cpu是几核的

    几个cpu more /proc/cpuinfo |grep "physical id"|uniq|wc -l 每个cpu是几核(假设cpu配置相同) more /proc/cpu ...

  7. 相机标定 matlab opencv ROS三种方法标定步骤(3)

    三 ,  ROS 环境下 如何进行相机标定 刚开始做到的时候遇到一些问题没有记录下来,现在回头写的时候都是没有错误的结果了,首先使用ROS标定相机, 要知道如何查看节点之间的流程图  rosrun r ...

  8. http请求的概念

    我曾多次阅读http协议,但是理解依然不深,在此,再次阅读,再次理解.加深两点:解析头部信息\r\n,分解头部和主体用\r\n\r\n.之所以一次请求会看到网络里有很多请求,是因为浏览器代替访问了多次 ...

  9. ONE WIRE

    以温度温度传感器为例 由三根线,分别为电源,信号,地线 使用GPIO口对信号线进行读操作 //初始化GPIO PC0端口void dht11_init(){ GPIO_InitTypeDef GPIO ...

  10. 关于在mfc中cstring转为float和ini

    CString str1,str, str2; GetDlgItemText(IDC_EDIT1, str1); GetDlgItemText(IDC_EDIT2, str2); UINT value ...