- Code: Select all
AC
Moderator: Board moderators
AC
Rene Decartes once said,
"I think, therefore I am.""R
Ie
n
te
h
iD
ne
kc
,a
r
tt
he
es
r
eo
fn
oc
re
e
s
Ia
i
ad
m,
.
"
AC
"I think, therefore I am."
Rene Decartes once said,R"
eI
n
et
h
Di
en
ck
a,
r
tt
eh
se
r
oe
nf
co
er
e
s
aI
i
da
,m
.
"#include <stdio.h>
int main(){
char input[100][100] = {'\0'};
int counter[100] = {0};
char ch;
int a = 0;
int b = 0;
int c = 0;
int h;
int i;
int nos = 0;
int high = 0;
while (scanf ("%c", &ch) != EOF) {
if (ch != '\n') {
if (ch != '\t'){
input[a][b] = ch;
b++;
}
} else {
counter[c] = b;
if (high <= b) {
high = b;
}
c++;
b = 0;
a++;
input[a][b] = ch;
}
nos = a;
}
a = nos - 1;
for (h = 0;h < high;) {
for (i = a; i >= 0; i--) {
printf("%c", input[i][h]);
}
printf("\n");
h++;
}
return 0;
}
brianfry713 wrote:For the sample input, you're printing null characters at the end of the last two lines.
for (j = 0; j < c; j++) {
temp = counter[j];
if (high > temp) {
min = high - temp;
for (k = min; k >= 0 ;) {
Tmin = temp+k;
input[j][Tmin] = ' ';
k--;
}
}
} #include <stdio.h>
int main(){
char input[100][100] = {'\0'};
int counter[100] = {0};
char ch;
int a = 0;
int b = 0;
int c = 0;
int h;
int i;
int j;
int k;
int temp;
int min = 0;
int Tmin = 0;
int nos = 0;
int high = 0;
while (scanf ("%c", &ch) != EOF) {
if (ch != '\n') {
if (ch != '\t'){
input[a][b] = ch;
b++;
}
} else {
counter[c] = b;
if (high <= b) {
high = b;
}
c++;
b = 0;
a++;
input[a][b] = ch;
}
nos = a;
}
for (j = 0; j < c; j++) {
temp = counter[j];
if (high > temp) {
min = high - temp;
for (k = min; k >= 0 ;) {
Tmin = temp+k;
input[j][Tmin] = ' ';
k--;
}
}
}
printf("\n");
a = nos - 1;
for (h = 0;h < high;) {
for (i = a; i >= 0; i--) {
printf("%d", input[i][h]);
}
printf("\n");
h++;
}
return 0;
}

Users browsing this forum: No registered users and 1 guest