ACM (UVa) : 490


#include <stdio.h>
#include <string.h>

int main ()
{
	char a [105] [105];
	int total = 0;
	int i, j;

	for (i = 0; i < 105; i++) { // assign blank space
		for (j = 0; j < 105; j++) 
			a [i] [j] = ' ';
	}

	while (gets (a [total])) // take all the inputs
		total++;

	// find the max length
	int max = 0;
	int length;
	for (i = 0; i < total; i++) {
		length = strlen (a [i]);
		if (length > max)
			max = length;
		a [i] [length] = ' ';
	}

	// output
	for (i = 0; i < max; i++) {
		for (j = total - 1; j >= 0; j--) 
			printf("%c", a [j] [i]);
		printf("\n");
	}

	return 0;
}

8 thoughts on “ACM (UVa) : 490

  1. @o
    我认为,以避免垃圾
    其实你不需要做同样的事情
    如果u可以以其他方式处理垃圾,那么它的确定

    顺便说一下,我不知道中文 🙂

    o :
    Why the first 25 lines have to add space

    Python :
    to avoid garbage i think
    actually u don’t need to do the same thing
    if u can handle garbage in other ways then its ok

  2. can u plz tell why i have to add blank spaces..without blank spaces output is still same..bt i got WA…thoug didnt get any garbage value ..totally confused…btw i am nobb 😛

  3. @RBN
    not all garbage values are visible
    what i mean is, there are some ASCII characters those are not visible

    run the following code and i hope you will find the reason 🙂

    
    #include <stdio.h>
    #include <string.h>
    
    int main (void)
    {
        char a [20] = "Hi";
        a [2] = 1;
        a [3] = 2;
        a [4] = 3;
        a [5] = '\0';
    
        printf ("String: %s\n", a);
    
        int len = strlen (a);
    
        printf ("Numbers: ");
    
        for ( int i = 0; i < len; i++ )
            printf ("%d ", a [i]);
    
        printf ("\n");
    
        return 0;
    }
    
  4. Bro, Can you tell me what is the problem with my code? It is getting WA. But i have done the same as you did.

    #include<stdio.h>
    #include<string.h>
    int main()
    {
        char sent[105][105];
        int i,j,len,count=0,max=0;
        for(i=0;i<105;i++){
            for(j=0;j<105;j++)
                sent[i][j]=' ';
        }
        while(gets(sent[count]))
        {
            len=strlen(sent[count]);
            if(len>max)
                max=len;
            count++;
        }
        for(i=0;i<max;i++)
        {
            for(j=count-1;j>=0;j--)
                printf("%c",sent[j][i]);
            printf("\n");
        }
        return 0;
    }
    
  5. bro can i use null character in the place of space?It is okay with space but i have got wa using null,
    why?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s