摘要:http://ac.jobdu.com/problem.php?cid=1040&pid=64题目描述: 对于一个十进制数A,将A转换为二进制数,然后按位逆序排列,再转换为十进制数B,我们乘B为A的二进制逆序数。 例如对于十进制数173,它的二进制形式为10101101,逆序排列得到10110101,其十进制数为181,181即为173的二进制逆序数。输入: 一个1000位(即10^999)以内的十进制数。输出: 输入的十进制数的二进制逆序数。样例输入:173样例输出:181// 题目65:10进制 VS 2进制.cpp: 主项目文件。 #include "stdafx.h&
阅读全文
随笔分类 - 九度机试教程
摘要:http://ac.jobdu.com/problem.php?cid=1040&pid=63题目描述:对N个长度最长可达到1000的数进行排序。输入:输入第一行为一个整数N,(1
#include #include using namespace std; const int N=101;
typedef struct Node
{ char str[1003]; int len;
}Node;
Node node[N]; bool cmp(Node m1,Node m2)
{ if(m1.len!=m2.len) return m1.len<m2.len; else ...
阅读全文
摘要:http://ac.jobdu.com/problem.php?cid=1040&pid=62题目描述:求2个浮点数相加的和题目中输入输出中出现浮点数都有如下的形式:P1P2...Pi.Q1Q2...Qj对于整数部分,P1P2...Pi是一个非负整数对于小数部分,Qj不等于0输入:对于每组案例,第1行是测试数据的组数n,每组测试数据占2行,分别是两个加数。每组测试数据之间有一个空行,每行数据不超过100个字符输出:每组案例是n行,每组测试数据有一行输出是相应的和。输出保证一定是一个小数部分不为0的浮点数样例输入:2
0.111111111111111111111111111111
0.
阅读全文
摘要:http://ac.jobdu.com/problem.php?cid=1040&pid=61题目描述:将M进制的数X转换为N进制的数输出。输入:输入的第一行包括两个整数:M和N(2
#include const int N=4003;
char str[N];//输入字符串
int start[N],ans[N],res[N]; //被除数,商,余数 //转换前后的进制
int oldBase;
int newBase; void change()
{//各个数位还原为数字形式 int i,len = strlen(str); start[0] = len; for(i=1;i...
阅读全文
摘要:http://ac.jobdu.com/problem.php?cid=1040&pid=60题目描述:输入一个正整数N,输出N的阶乘。输入:正整数N(0
#include const int N=1003;
int aa[N];
int size; void mul(int n)
{ int in=0; for(int i=0;i=0;i--) printf("%04d",aa[i]); printf("\n");
} int main()
{ int n; while(scanf("%d",&n)!=EOF) {
阅读全文
摘要:http://ac.jobdu.com/problem.php?cid=1040&pid=59题目描述:实现一个加法器,使其能够输出a+b的值。输入:输入包括两个数a和b,其中a和b的位数不超过1000位。输出:可能有多组测试数据,对于每组数据,输出a+b的值。样例输入:2 6
10000000000000000000 10000000000000000000000000000000样例输出:8
10000000000010000000000000000000// 题目60:a+b.cpp: 主项目文件。 #include "stdafx.h"
#include
#
阅读全文
摘要:http://ac.jobdu.com/problem.php?cid=1040&pid=57题目描述:Xinlv wrote some sequences on the paper a long time ago, they might be arithmetic or geometric sequences. The numbers are not very clear now, and only the first three numbers of each sequence are recognizable. Xinlv wants to know some numbers i
阅读全文
摘要:http://ac.jobdu.com/problem.php?cid=1040&pid=56题目描述:求A^B的最后三位数表示的整数。说明:A^B的含义是“A的B次方”输入:输入数据包含多个测试实例,每个实例占一行,由两个正整数A和B组成(1 int pow(int a,int n)
{ if(n==1) return a; int res=1; if(n&0x01) res=a%1000; int tmp=pow(a,n>>1); res=(res*((tmp*tmp)%1000))%1000; return res;
} int main(array ^arg
阅读全文
摘要:http://ac.jobdu.com/problem.php?cid=1040&pid=55题目描述:输入n个整数,依次输出每个数的约数的个数输入:输入的第一行为N,即数组的个数(N
#include #include const int N=31650;
bool prime[N]; void selectPrime()
{ memset(prime,0,sizeof(prime)); prime[0]=prime[1]=true; for(int i=2;i<N;i++) { if(!prime[i]) { for(int j=i+i;j<N;j+=i) ...
阅读全文
摘要:http://ac.jobdu.com/problem.php?cid=1040&pid=54题目描述:给定n,a求最大的k,使n!可以被a^k整除但不能被a^(k+1)整除。输入:两个整数n(2
#include #include const int N=1001;
bool prime[N];
int base_n[N];
int base_a[N]; void selectPrime()
{ memset(prime,0,sizeof(prime)); prime[0]=prime[1]=true; for(int i=2;i<N;i++) { if(!prime[i...
阅读全文
摘要:http://ac.jobdu.com/problem.php?cid=1040&pid=53题目描述:求正整数N(N>1)的质因数的个数。相同的质因数需要重复计算。如120=2*2*2*3*5,共有5个质因数。输入:可能有多组测试数据,每组测试数据的输入是一个正整数N,(1
#include const int N=31650;
bool used[N]; void selectPrime()
{ memset(used,0,sizeof(used)); used[0]=used[1]=true; for(int i=2;i<N;i++) { if(!used[i]) .
阅读全文
摘要:http://ac.jobdu.com/problem.php?cid=1040&pid=52题目描述:Goldbach's Conjecture: For any even number n greater than or equal to 4, there exists at least one pair of prime numbers p1 and p2 such that n = p1 + p2.This conjecture has not been proved nor refused yet. No one is sure whether this conjec
阅读全文
摘要:http://ac.jobdu.com/problem.php?cid=1040&pid=51题目描述:Output the k-th prime number.输入:k≤10000// 题目52:Prime Number.cpp: 主项目文件。 #include "stdafx.h"
#include #include const int N=104733;
bool used[N];
const int M=10003;
int prime[M]; int selectePrime(int n)
{ memset(used,0,sizeof(used)); in
阅读全文
摘要:http://ac.jobdu.com/problem.php?cid=1040&pid=49题目描述:给定一个数n,要求判断其是否为素数(0,1,负数都是非素数)。输入:测试数据有多组,每组输入一个数n。输出:对于每组输入,若是素数则输出yes,否则输入no。样例输入:13// 题目50:素数判定.cpp: 主项目文件。 #include "stdafx.h"
#include #include bool isPrime(int n)
{ if(n<=1) return false; int tt=(int)sqrt(1.0*n); for(int i=2;
阅读全文
摘要:http://ac.jobdu.com/problem.php?cid=1040&pid=50题目描述:输入一个整数n(2
#include bool isPrime(int n)
{ if(n<=1) return false; int tt=(int)sqrt(1.0*n); for(int i=2;i<=tt;i++) if(n%i==0) return false; return true;
} int main()
{ int n; while(scanf("%d",&n)!=EOF) { bool flag=true; for(int
阅读全文
浙公网安备 33010602011771号