目录
1019 General Palindromic Number (20分)
1019 General Palindromic Number (20分)
Sample Input 1:
27 2
Sample Output 1:
Yes
1 1 0 1 1
Sample Input 2:
121 5
Sample Output 2:
No
4 4 1
解释:27转换成二进制=11011,是回文数,输出Yes
#include<iostream>
using namespace std;
int N,c;
int a[1000];//倒序
int b[1000];//正序
void CheckNum(){
int n,m,temp;
int h1=0; n=N;
while(n){
temp=n%c;
a[h1++]=temp;
n/=c;
}
int h2=h1,u=0;
for(int i=h1-1;i>=0;i--){
b[u++]=a[i];
}
int flag=0;
for(int i=0;i<h2;i++){
if(a[i]!=b[i]) {
flag=1; break;
}
}
if(flag)
cout<<"No\n";
else
cout<<"Yes\n";
for(int j=0;j<h2-1;j++)
cout<<b[j]<<" ";
cout<<b[h2-1]<<endl;
}
int main(){
cin>>N>>c;
CheckNum();
return 0;
}
1027 Colors in Mars (20分)
Sample Input:
15 43 71
Sample Output:
#123456
解释:把r,g,b三个10进制数字转化为 13进制的数
#include<cmath>
#include<iostream>
#include <cstdio>
#include <stdlib.h>
#include <algorithm>
using namespace std;
char radix[13]={'0','1','2','3','4','5','6','7','8','9','A','B','C'};
int main(){
int r,g,b;
scanf("%d%d%d",&r,&g,&b);
printf("#");
printf("%c%c",radix[r/13],radix[r%13]);
printf("%c%c",radix[g/13],radix[g%13]);
printf("%c%c",radix[b/13],radix[b%13]);
return 0;
}
1058 A+B in Hogwarts (20分)
If you are a fan of Harry Potter, you would know the world of magic has its own currency system -- as Hagrid explained it to Harry, "Seventeen silver Sickles to a Galleon and twenty-nine Knuts to a Sickle, it's easy enough." Your job is to write a program to compute A+B where A and Bare given in the standard form of Galleon.Sickle.Knut
(Galleon
is an integer in [0,107], Sickle
is an integer in [0, 17), and Knut
is an integer in [0, 29)) 注意区间开闭
Sample Input:
3.2.1 10.16.27
Sample Output:
14.1.28
解释:从低位到高位,以此满足a+b满29进1,满17进1,满108进1;
#include<cmath>
#include<iostream>
#include <cstdio>
#include <stdlib.h>
#include <algorithm>
using namespace std;
int main(){
int a[3],b[3],c[3];
scanf("%d.%d.%d %d.%d.%d",&a[0],&a[1],&a[2],&b[0],&b[1],&b[2]);
int carry=0; //进位
c[2]=(a[2]+b[2])%29; carry=(a[2]+b[2])/29;
c[1]=(a[1]+b[1]+carry)%17; carry=(a[1]+b[1]+carry)/17;
c[0]=(a[0]+b[0])+carry;
printf("%d.%d.%d",c[0],c[1],c[2]);
return 0;
}