harumakigohan686

这里先埋个坑(

#CP1025. 陈述句变成疑问句

还是有点小bug后面再调吧

#include <stdio.h>
#include <ctype.h>
#include <string.h>
int main()
{
    char a[100];
    char b[100]; //第一个单词
    char c[100]; //第二个单词
    char d[100]; //其余剩下的单词
    int i,y,x,f,j=0,k=0,l=0;
    gets(a);
    f=strlen(a);
    for(i=0; a[i]!='\0'; i++)
    {
        b[j]=a[i];
        j++;
        if(a[i+1]==' ')
        {
            break;
        }
    }
    b[j]='\0';
    if(i==f)
    {
        for(int t=0; t<j-1; t++)
        {
            printf("%c",b[t]);
        }
        printf("?");
        return 0;
    }
    for( y=i+1; a[y]!='\0'; y++)
    {
        c[k]=a[y];
        k++;
        if(a[y+1]==' ')
        {
            break;
        }
    }
    c[k]='\0';
    if(f==y)
    {
        for(int t=0; t<k-1; t++)
        {
            if(c[t]!=' ')
            {
                if(t==1)
                {
                    printf("%c",c[t]-32);
                    continue;
                }
                printf("%c",c[t]);
            }
        }
        printf(" ");
        for(int t=0; t<j; t++)
        {
            if(b[t]!=' ')
            {
                if(t==0)
                {
                    printf("%c",b[t]+32);
                    continue;
                }
                printf("%c",b[t]);
            }
        }
        printf("?");
        return 0;
    }
    for( x=y+1; a[x]!='\0'; x++)
    {
        d[l]=a[x];
        l++;
        if(a[x+1]=='\0')
        {
            break;
        }
    }
    d[l]='\0';
    for(int t=0; t<k; t++)
    {
        if(c[t]!=' ')
        {
            if(t==1)
            {
                printf("%c",c[t]-32);
                continue;
            }
            printf("%c",c[t]);
        }
    }
    printf(" ");
    for(int t=0; t<j; t++)
    {
        if(b[t]!=' ')
        {
            if(t==0)
            {
                printf("%c",b[t]+32);
                continue;
            }
            printf("%c",b[t]);
        }
    }
    for(int t=0; t<l-1; t++)
    {
        printf("%c",d[t]);
    }
    printf("?");
    return 0;
}

posted on 2023-01-06 11:08  harumakigohan  阅读(23)  评论(0)    收藏  举报