1027. 二进制表示
输入一个字符,输出其八位二进制表示。
输入格式
在一行输入一个可打印字符 c。
输出格式
在一行中输出c的二进制表示。
#include<stdio.h>
int main()
{
char c;
int i = 8;
char res[8];
scanf("%c", &c);
while(--i != -1)
{
res[i] = '0' + c % 2;
c /= 2;
}
printf("%s", res);
}
1028. Maximum product
Given a positive integer (), find the list of positive integers whose product is the largest among all the lists of positive integers whose sum is , and print the maximum product.
输入格式
Only one line, containing the integer .
输出格式
Only one line, representing the maximum product.
// 可能跟e的性质有关吧,反正就是尽量凑足够多的3出来,其次是2
#include<stdio.h>
#include<math.h>
int f(int N) {
if (N == 1 || N == 2)
return N;
int max = N;
for (int i = 1; i < N; i++) {
int tmp = i * f(N - i);
if (tmp > max)
max = tmp;
}
return max;
}
int main()
{
int input;
scanf("%d", &input);
if(input < 4) printf("%d", input);
else
{
long long pro = 1;
while(input > 4)
{
input -= 3;
pro *= 3;
}
pro *= input;
printf("%lld", pro);
}
}
1029. Compute e
#include<stdio.h>
int main()
{
double e = 0;
int cnt = 1;
double denominator = 1.0;
while(1.0 / denominator > 1e-9)
{
e += 1.0 / denominator;
denominator *= cnt++;
}
printf("%.6lf", e);
}
1030. Rotate digits
#include<stdio.h>
// 字符串实现,其实直接开两个字符串更方便一点
int main()
{
long long data, num, cnt = 0;
scanf("%lld %lld", &data, &num);
if(data < 10)
{
printf("1 %d", data);
return 0;
}
long long tmp = data;
char str[200];
for(int i = 0 ; i < 200; i++) str[i] = 0;
while(tmp)
{
str[100 - cnt++] = '0' + tmp % 10;
tmp /= 10;
}
//字符串要倒着
num %= cnt;
for(int i = 0; i < num; i++)
{
//由于右转,所以是从右往左平移
str[100 - i - cnt] = str[100 - i];
str[100 - i] = 0;
}
// 去掉在开头0
while(*(str - cnt - num + 101) == '0')
num--;
printf("%d %s",cnt ,(str - cnt - num + 101));
}