参赛经历

本来是去初学者试炼营,偶然点进小白赛,发现参赛的方式不是很复杂,蛮试一下

A题

Tokitsukaze and New Operation

1.png
2.png

我的思路是用模10,除10的方法遍历每位数,再去做,途中也遇到很多问题,相乘小于10,要乘的10的不同次方,在解决种种问题后,自测运行过了

判断位数是否一致

int istrue(int x, int y)
{
int countx = 0;
int county = 0;
do
{
x = x / 10;
countx++;
}while (x != 0);
do
{
y = y / 10;
county++;
}while (y != 0);
if (countx == county)
return 1;
else
return 0;
}

计算各位数相乘

int cacux(int x, int y)
{
int count = 0;
int num = x;//注意x的值不能变,引入变量
do
{
num = num / 10;
count++;
}while (num != 0);
//printf("%d\n", count);
int i = 0;
int ret = 0;
int j = 0;
for (i = 0; i < count; i++)
{
ret += (x % 10) * (y % 10) * pow(10, j);
if ((x % 10) * (y % 10) < 10)
j = j + 1;
else
j = j + 2;
x = (x - (x % 10)) / 10;
y = (y - (y % 10)) / 10;
//printf("%d %d %d\n", ret, x, y);
//为0的话就不能往上,<10

}
return ret;
}

主函数

int main()
{
int num = 0;
scanf("%d", &num);
int i = 0;
int x = 0;
int y = 0;
int a[100] = {0};
for (i = 0; i < num; i++)
{
scanf("%ld %ld", &x, &y);
if (istrue(x, y) == 1)
{
a[i] = cacux(x, y);
}
else
a[i] = -1;

}
for (i = 0; i < num; i++)
{
printf("%d\n", a[i]);
}
return 0;
}

自测运行

3.png

后面也找出问题了,数字太大越界了,尝试了long long还是不行,看了别人的解答发现根本看不懂。

😩