解题思路:
传统思路
注意事项:
遇到多个空格直接返回上一行qaq
参考代码:
#include<stdio.h>
#include<string.h>
#define HANG 100
#define LIE 100
int main(void)
{
int hang = 0,cot = 0, lie = 0, counst = 0;
char del_sapce[HANG][LIE] = { '\0' };
for (; hang < HANG; hang++)
{
gets_s(del_sapce[hang], HANG);
if (strcmp(del_sapce[hang], "End of file") == 0)
{
break;
}
cot++;
}
for (lie = 0; counst < cot; counst++)
{
int m = 0;
m = 0;
lie = 0;
while (del_sapce[counst][lie++] != '\0')
{
m++;
}
lie = 0;
while (del_sapce[counst][lie] != '\0')
{
if (del_sapce[counst][lie] == ' ')
{
int n = 0;
for (n = 0; n < (m - lie); n++)
{
char* p_1 = del_sapce[counst];
char* p_2 = del_sapce[counst];
*(p_1 + lie + n) = *(p_2 + lie + n + 1);
}
if (del_sapce[counst][lie] == ' ')
{
counst -= 1;
}
}
lie++;
}
}
for (hang = 0; hang < cot; hang++)
{
puts(del_sapce[hang]);
}
return 0;
}
0.0分
0 人评分
Minesweeper (C语言代码)浏览:856 |
简单编码 (C++代码)浏览:731 |
矩阵乘法 (C++代码)浏览:1662 |
字符串比较 (C语言代码)答案错误????浏览:641 |
C语言程序设计教程(第三版)课后习题7.2 (C语言代码)浏览:686 |
C语言程序设计教程(第三版)课后习题11.8 (C语言代码)浏览:910 |
WU-C语言程序设计教程(第三版)课后习题12.1 (C++代码)浏览:1024 |
关于float,double变量的几点说明浏览:1926 |
杨辉三角 (C语言代码)浏览:505 |
矩阵转置 (C语言代码)浏览:855 |