-
Notifications
You must be signed in to change notification settings - Fork 2
/
10293.c
executable file
·102 lines (88 loc) · 1.67 KB
/
10293.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#include <stdio.h>
#include <string.h>
#include <ctype.h>
void removePunct( char *str )
{
int i = 0 ;
for( i = 0 ; str[ i ] != '\0' ; i++ )
{
if( isalpha( str[ i ] ) == 0 && str[ i ] != '-' )
{
str[ i ] = ' ' ;
}
else
{
str[ i ] = tolower( str[ i ] ) ;
}
}
}
int main()
{
char buffer[ 205 ] = { 0 };
char pre_buffer[ 205 ] = { 0 };
int len[ 35 ] = { 0 } ;
char *word = 0 ;
int i = 0 ;
strcpy( pre_buffer, "" ) ;
/* read in the article */
while( 1 )
{
gets(buffer) ;
if( strlen( buffer ) == 0 )
{
break ;
}
for( i = 0 ; i <= 30 ; i++ )
{
len[ i ] = 0 ;
}
while( buffer[ 0 ] != '#' )
{
strcat( pre_buffer, buffer ) ;
strcpy( buffer, pre_buffer ) ;
strcpy( pre_buffer, "" ) ;
for( i = 0 ; buffer[ i ] != '\0' ; i++ )
{
if( buffer[ i ] == '\'' )
{
strcpy(buffer+i, buffer+i+1) ;
i-- ;
}
}
for( i = 0 ; buffer[ i+1 ] != '\0' ; i++ )
{
if( buffer[ i ] == '-' )
{
strcpy(buffer+i, buffer+i+1) ;
i-- ;
}
}
/* remove punctuation from the string and lower the alphabetical letters */
removePunct( buffer ) ;
/* extract words from a string */
word = strtok( buffer, " " ) ;
while( word != NULL )
{
if( word[ strlen(word)-1 ] != '-' )
{
len[ strlen(word) ] ++ ;
}
else
{
strcpy( pre_buffer, word ) ;
}
word = strtok( NULL, " " ) ;
}
gets(buffer) ;
}
for( i = 0 ; i <= 30 ; i++ )
{
if( len[ i ] != 0 )
{
printf("%d %d\n",i,len[i]) ;
}
}
printf("\n");
}
return 0 ;
}