00-自测4. Have Fun with Numbers (20)

时间:2021-06-26 17:03:37
#include <stdio.h>
#include <ctype.h>
int main()
{
        int b, j = 0, a[20];
        char c[20], *d;
        do
        {
                c[j] = getchar();
                d = &c[j];
                j++;
        }
        while (isdigit(*d));//判断输入是否为数字 遇其他字符结束

        if ((c[0] - '0') < 5)
        {
                printf("Yes\n");
                int g=0;
                for (b = 0; b < j - 1; b++)
                {
                        a[b] = (c[b] - '0');
                        // printf("%d",a[b]);
                }
                for (b = j - 2; b >= 0; b--)
                {
                        if (a[b] > 4)
                        {
                                a[b] = ((a[b]) * 2) % 10;
                                a[b] += g;
                                g = 1;
                        }
                        else if (a[b] < 5)
                        {
                                a[b] *= 2;
                                a[b] += g;
                                g = 0;
                        }
                        //printf("%d", a[b]);
                }
                for (b = 0; b < j - 1; b++)
                {
                        printf("%d", a[b]);
                }
        }
        else if ((c[0] - '0') > 4)
        {
                printf("No");
        }
}