thirteenth exercise
This commit is contained in:
parent
dc252d40ff
commit
e1973de228
|
@ -0,0 +1,44 @@
|
|||
#include <stdio.h>
|
||||
|
||||
// version 1.0
|
||||
#define ARR_LENGTH 20
|
||||
int main(){
|
||||
int arr[ARR_LENGTH];
|
||||
int c, index, i, dashes, nc;
|
||||
index = i = dashes = nc = 0;
|
||||
while ((c = getchar()) != '\n' && i < ARR_LENGTH-1){
|
||||
if (c == ' ' && nc != 0){
|
||||
arr[index]=nc;
|
||||
nc=0;
|
||||
index++;
|
||||
}
|
||||
else {
|
||||
nc++;
|
||||
}
|
||||
}
|
||||
while (i < index){
|
||||
while (dashes<arr[i]){
|
||||
putchar('-');
|
||||
dashes++;
|
||||
}
|
||||
dashes=0;
|
||||
putchar('\n');
|
||||
i++;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// version 2.0
|
||||
int main(){
|
||||
int c;
|
||||
while ((c = getchar()) != '\n'){
|
||||
if (c != ' '){
|
||||
putchar('-');
|
||||
}
|
||||
else {
|
||||
putchar('\n');
|
||||
}
|
||||
}
|
||||
putchar('\n');
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue