Could anyone send me some input, or take a look at my code (It's easy - it have one function to read word and one for output it

Best regards
DM
Moderator: Board moderators
Code: Select all
1
abcde
abcd
abcd
abc
abc
ab
a
abcde
.abcd
..abcd
...abc
...abc
..ab
.a
Dominik Michniewski wrote:Thanks Adil for helpfull IO
I should go to vacationI'm starting to do silly mistakes
This time I don't consider moment, in which words end, so I got
abcde
.abcd
..abcd
...abc
....abc <- one more space ...
..ab
.a
And this one space causes me WA ...
Thanks
DM
Code: Select all
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX 15
#define SIZE 100001
int compare_strings(char* s1, char* s2)
{
int count = 0;
for( ; *s1 == *s2; *s1++, *s2++) count++;
return count;
}
int main()
{
char strArr[SIZE][MAX];
int CASES, i, j, sp, count, y;
scanf("%d\n", &CASES);
i = 0;
while(CASES--) {
i = 0;
while(1) {
fgets(strArr[i], MAX, stdin);
strArr[i][strlen(strArr[i])-1] = '\0';
if(strArr[i][0] == '\0') break;
i++;
}
/* output */
count = 0;
printf("%s\n", strArr[0]);
for(j=1;j<i;j++) {
sp = compare_strings(strArr[j], strArr[j-1]);
if(sp == 0) count = 0;
else if(sp > count) count++;
else if(sp < count) count = sp;
for(y=0;y<count;y++) putchar(32);
printf("%s\n", strArr[j]);
}
if(CASES-1 >= 0) putchar('\n');
}
return 0;
}