/*
北航机试真题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
*/
2014-3
最新推荐文章于 2022-10-14 00:33:06 发布