2014-3

/*
北航机试真题2020/4/25
第二遍
*/

#include<stdio.h>
#include<string.h>

int line;
    char str[120];
    char temp[120];
    char before[120];
    char after[120];
int count_n = 0;
int count_before = 0;
int count_after = 0;

int cmpSpace(char c)
{
    if(c == ' ' || c == '\t' || c=='\n')
        return 1;
    return 0;
}

void precess()
{
    count_n = 0;
    int i = 0;
    while(cmpSpace(str[i]))//去除开头的空格
    {
        i++;
    }
    for( ;i<strlen(str); )
    {
        if( cmpSpace(str[i]))
        {
            temp[count_n++] = str[i];
            while( cmpSpace(str[i]) )
                i++;
        }
        else
        {
            temp[count_n++] = str[i++];
        }
    }
    temp[count_n] = '\0';
    //printf("%s000\n",temp);
}

void splite_temp()
{
    count_before = 0;
    count_after = 0;

    int i ;
    for(i = 0;i<strlen(temp);i++)
    {
        if(temp[i] != ':')
        {
            before[count_before++] = temp[i];
        }
        if(temp[i] == ':')
        {
            break;
        }
    }
    before[count_before] = '\0';

    for(i = i + 1;i<strlen(temp);i++)
    {
        after[count_after++] = temp[i];
    }
    after[count_after] = '\0';

    //printf("%s111\n %s222\n",before,after);
}
int main()
{
    scanf("%d",&line);
    getchar();
    while( gets(str) != NULL)
    {
        precess();
        splite_temp();
        if(cmpSpace(before[count_before - 1]))
        {
            for(int i = 0;i<line - count_before;i++)
                printf(" ");
            printf("%s:",before);
        }
        else
        {
            for(int i = 0;i<line-count_before-1;i++)
            {
                printf(" ");
            }
            printf("%s :",before);
        }

        if(cmpSpace(after[0]))
        {
            printf("%s\n",after);
        }
        else
        {
            printf(" %s\n",after);
        }
    }
    return 0;
}

/*
30
amy thomas1:alice
                 amy thomas1 : alice
amy thomas2   :    alice
                 amy thomas2 : alice
   jackson yee   :          jack
                 jackson yee : jack
   tom        :tim
                         tom : tim
^Z
*/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值