Dadao153 @ 2024-12-22 20:23:41
题目是数字反转,自己把可能的特殊值和大数小数,上限都试过了,都是对的,错了三个测试点,代码如下。
#include<stdio.h>
int i;
int s[10000];
void daoxu(long long n) {
for (i=0; n != 0; i++) {
s[i] = n % 10;
n = n / 10;
}
}
int main() {
long long m = 0,k=0;
scanf("%lld", &m);
k = m;
if (m < 0)m = -m;
daoxu(m);
if (m == 0)printf("0");
if (k >= 0) {
for (int p = 0; p < i; p++) {
if (s[p] != '\0')printf("%d", s[p]);
}
}
else if (k < 0) {
printf("-");
for (int p = 0; p < i; p++) {
if (s[p] != '\0')printf("%d", s[p]);
}
}
return 0;
}
by pika_ @ 2024-12-22 20:30:45
hack:
input:
-10000000001
your:
-11
ans:
-10000000001
by hahadamntards @ 2024-12-23 22:50:40
#define _CRT_SECURE_NO_WARNINGS 1
#include <math.h>
#include <stdio.h>
int main()
{
int n,x,a,i=0, sum = 0,b,c;
scanf("%d", &n);
/*求+-号*/
x = n > 0 ? 1 : -1;
n = fabs(n);
c = n;
while (c!= 0)
{
c /= 10;
i++;
}
for (int j = i - 1; j >= 0; j--)
{
a = n % 10;
n /= 10;
sum +=a*pow(10, j);
}
printf("%d\n",sum*x);
return 0;
}