洛谷ide的运行为啥很奇怪

P1957 口算练习题

cxkssss678 @ 2022-10-23 14:40:30

ide里第一次循环不进行输入操作,但是进行了输出操作,想循环三次,每次输入一个字符串,但在ide里必须写成4次循环。 这是为啥????


by Troilus @ 2022-10-23 14:50:45

代码呢?


by Resolute_Faith @ 2022-10-23 15:00:51

你也很奇怪


by _SkyDream_ @ 2022-10-23 17:14:48

你写错了


by _SkyDream_ @ 2022-10-23 17:17:11

我觉得你写成了(i=1;i<3;i++)


by cxkssss678 @ 2022-10-24 09:20:33

#include<stdio.h>
#include<string.h>
void doo(int x, int y, char c)
{
    int s = 0;
    int count = 2;
    if (x <= 0)count++;
    if (y <= 0)count++;
    switch (c)
    {
    case 'a':
        s = x + y;
        printf("%d+%d=%d\n", x, y, s);
        if (s <= 0) count++;
        while (x != 0)
        {
            count++;
            x = x / 10;
        }
        while (y != 0)
        {
            count++;
            y = y / 10;
        }
        while (s != 0)
        {
            count++;
            s = s / 10;
        }
        printf("%d", count);
        break;
    case 'b':
        s = x - y;
        printf("%d-%d=%d\n", x, y, s);
        if (s <= 0) count++;
        while (x != 0)
        {
            count++;
            x = x / 10;
        }
        while (y != 0)
        {
            count++;
            y = y / 10;
        }
        while (s != 0)
        {
            count++;
            s = s / 10;
        }

        printf("%d", count);
        break;
    case 'c':
        s = x * y;
        printf("%d*%d=%d\n", x, y, s);
        if (s <= 0) count++;
        while (x != 0)
        {
            count++;
            x = x / 10;
        }
        while (y != 0)
        {
            count++;
            y = y / 10;
        }
        while (s != 0)
        {
            count++;
            s = s / 10;
        }
        printf("%d", count);
}

}
int main()
{
    int n;
    scanf("%d", &n);
    getchar();
    int x, y;
    char c='!';
    char S[100] = { 0 };
    for (int i = 0; i <= n; i++)
    {
        memset(S, 0, sizeof(S));
        gets(S);
        if (S[0] == 'a' || S[0] == 'b' || S[0] == 'c')
        {
            c = S[0];
            sscanf(S, "%*[a-z ]%d %d",&x, &y);
        }
        else
        {
            sscanf(S, "%d %d", &x, &y);
        }
        doo(x, y, c);
        if (i < n && i!=0 ) printf("\n");
    }
    return 0;
}

@tsqx_nia_qute


by cxkssss678 @ 2022-10-24 09:21:35

@tsqx_nia_qute 没粘贴上,尴尬


by cxkssss678 @ 2022-10-24 09:25:36

@horray_for_bfs_dfs 没有我想写的是for(int i=0;i<4;i++) 然后在ide里第一次循环只输出换行,不进行输入,后来变成for(int i=0;i<=4;i++)就过了


by cxkssss678 @ 2022-10-24 09:32:02

@tsqx_nia_qute 这是AC的,多进行了一次循环


by cxkssss678 @ 2022-10-24 09:33:46

@Resolute_Faith 你是牛的,给你点赞


by zyz123789 @ 2022-10-28 15:26:34

你是我见到的第一个用gets的人


|