UVALive 4874 进制转换
来源:互联网 发布:java中的init方法 编辑:程序博客网 时间:2024/06/07 03:03
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cctype>
#include <cstdlib>
#define MAX 10000
using namespace std;
int M,N;
int B;
int x[MAX];
int y[MAX];
int To_B(int n,int a[])
{
//cout<<"***\n";
int count = 0;
while(1)
{
a[count++] = n % B;
n /= B;
if(n == 0) break;
}
// cout<<count<<endl;
return count;
}
int deal()
{
//cout<<"deal\n";
int len1 = To_B(M,x);
int len2 = To_B(N,y);
int temp[MAX];
memset(temp,0,sizeof(temp));
int i,cc = 0;
for( i = 0;i < len1 || i < len2;i++)
temp[cc++] = (x[i]+y[i])%B;
int r = 0;
int ff = 1;
for(int k = 0;k < cc;k++)
{
r += temp[k] * ff;
ff *= B;
}
return r;
}
int main()
{
freopen("in.in","r",stdin);
int test_case;
cin>>test_case;
while(test_case--)
{
int cas;
cin>>cas;
cout<<cas<<" ";
cin>>B>>M>>N;
memset(x,0,sizeof(x));
memset(y,0,sizeof(y));
int temp = deal();
cout<<temp<<endl;
}
return 0;
}
- UVALive 4874 进制转换
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- 读书笔记 节选示例
- Unix常用命令
- 如何使用VS写单元测试(转自:http://www.51crazy.net/Article/216.aspx)
- UVALive 4873
- Java 理论与实践: 构建一个更好的 HashMap ConcurrentHashMap
- UVALive 4874 进制转换
- JavaScript实现动态添加,删除行
- 队的链式实现
- UVALive 4877 记忆搜索
- linux查找命令/find/locate/whereis/which/type
- HTTP协议详解
- jmesa 使用和导出中文excel,pdf数据处理
- 全面剖析XMLHttpRequest对象
- poj 3298 Antimonotonicity DP