题解 | The Biggest Water Problem
The Biggest Water Problem
https://www.nowcoder.com/practice/435aa556e093463891f6da7d322140a4
#include <stdio.h>
int main() {
long int n;
long int sum = 0;//第一次判断
long int sum1 = 0;//第二次
long int sum2 = 0;//特殊情况(数较大时)
scanf("%ld", &n);//输入整数
while (n != 0)//第一次变
{
long int a = n % 10;
sum += a;
n /= 10;
}
if (sum < 10)
{
printf("%ld\n", sum);
}
else //继续变身
{
while (sum != 0)
{
long int c = sum % 10;
sum1 += c;
sum /= 10;
}
if (sum1 >= 10)
{
while (sum1 != 0)
{
long int a = sum1 % 10;
sum2 += a;
sum1 /= 10;
}
printf("%ld\n", sum2);
}
else
{
printf("%ld\n", sum1);
}
}
return 0;
}
C语言基础 文章被收录于专栏
里面较为详细的介绍了c语言的相关用法和有关题目。
