468 - Key to Success

All about problems in Volume 4. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

htl
Experienced poster
Posts: 185
Joined: Fri Jun 28, 2002 12:05 pm
Location: Taipei, Taiwan

468 - Key to Success

Post by htl » Sat Jul 10, 2004 10:40 am

Could someone give some critical case of input?

htl
Experienced poster
Posts: 185
Joined: Fri Jun 28, 2002 12:05 pm
Location: Taipei, Taiwan

Post by htl » Sat Jul 10, 2004 6:30 pm

I set the buffer to 3000 characters and get WA. I get PE after setting the buffer to 6000 characters. Than's strange. Now I don't know how to fix the PE.

Guest
New poster
Posts: 39
Joined: Wed May 19, 2004 5:52 pm
Location: Dhaka, Bangladesh
Contact:

WA

Post by Guest » Sat Aug 28, 2004 6:02 pm

Hello,
First I got RTE, fixed it, now I got WA :( , but this time I could not fix it.
Can anyone enlighten me? :cry:
Thanks in advance.

Here's my code:
[c]Code Removed[/c]
Last edited by on Sun Aug 29, 2004 7:39 am, edited 1 time in total.

Ryan Pai
Learning poster
Posts: 67
Joined: Fri Jul 04, 2003 9:59 am
Location: USA
Contact:

Post by Ryan Pai » Sat Aug 28, 2004 8:54 pm

One thing I noticed is that you have:

Code: Select all

for(i=0;i<26;i++)
I assume 26 is there because there are 26 letters. But this problem says that capital are distinct from lowercase, so this should be 52
Last edited by Ryan Pai on Fri Jul 08, 2005 5:21 pm, edited 1 time in total.
I'm always willing to help, if you do the same.

Ryan Pai
Learning poster
Posts: 67
Joined: Fri Jul 04, 2003 9:59 am
Location: USA
Contact:

Post by Ryan Pai » Sat Aug 28, 2004 9:13 pm

This is where I double posted and looked goofy.
Last edited by Ryan Pai on Sun Aug 29, 2004 7:50 am, edited 1 time in total.
I'm always willing to help, if you do the same.

Guest
New poster
Posts: 39
Joined: Wed May 19, 2004 5:52 pm
Location: Dhaka, Bangladesh
Contact:

AC

Post by Guest » Sun Aug 29, 2004 7:43 am

Hello Ryan,
Thank you for pointing out my mistake. It was a silly one. :wink: I forgot to change that 26 to 256 after noticing that the code should be case sensitive. Now I've got AC :D
Regards,

abhijit
New poster
Posts: 12
Joined: Mon May 24, 2004 2:13 pm

Post by abhijit » Tue Feb 08, 2005 6:52 pm

i get an ouput-limit-exceeded on this.
isn't it always the case for each input set, the output line is as long as the 2nd line in the input set ?

yiuyuho
A great helper
Posts: 325
Joined: Thu Feb 21, 2002 2:00 am
Location: United States
Contact:

Post by yiuyuho » Sat Feb 12, 2005 1:52 am

yes, that is the case, if you still care, :lol:

yiuyuho
A great helper
Posts: 325
Joined: Thu Feb 21, 2002 2:00 am
Location: United States
Contact:

Post by yiuyuho » Sat Feb 12, 2005 3:14 am

This is weird, I submitted 2 versions of code, one treating uppercase and lowercase as different letters, and one treating upper and lower as same letter, but output them according to their case. Both get PE :o

So which way is intened by the problem setter?

User avatar
Ali Arman Tamal
Learning poster
Posts: 76
Joined: Sat Jan 15, 2005 5:04 pm
Location: Dhaka
Contact:

Post by Ali Arman Tamal » Tue Feb 15, 2005 5:13 am

Hello ! :)


yiuyuho wrote:
This is weird, I submitted 2 versions of code, one treating uppercase and lowercase as different letters, and one treating upper and lower as same letter, but output them according to their case. Both get PE
Problem description says:
The outputs of two consecutive cases will be separated by a blank line.
Note: You have to print a newline even after the last test case (though it is not said).

User avatar
smilitude
Experienced poster
Posts: 137
Joined: Fri Jul 01, 2005 12:21 am

468 - WA!

Post by smilitude » Sat Oct 08, 2005 1:54 am

what 's wrong?
I dont know...
Do you?

Code: Select all

/*
468 - key to success 
submission 1 runtime error 2 runtime error 3 WA 4 WA
coded at 5:08pm on 6th oct 05

comment: did i make it complex? i dont think so!
*/


#include <stdio.h>
#include <string.h>
#include <ctype.h>
#define MAX 10000

int main() {
	char not_encoded[MAX+1],encoded[MAX+1];
	int i,j,len;
	int tcases;
	char flag=0;
	struct{
		char ch;
		int occ;
	}lower[52],higher[52],temp;

	scanf("%d",&tcases);
	for(;tcases>0;tcases--) {
		scanf("%s",not_encoded); 
		scanf("%s",encoded);
		len=strlen(not_encoded);
		if(flag) printf("\n");

		for(i=0;i<26;i++) {
			lower[i].ch=i+'a';
			higher[i].ch=i+'a';
			higher[i].occ=0;
			lower[i].occ=0;
		}

		for(i=26;i<52;i++) {
			lower[i].ch=i+'A'-26;
			higher[i].ch=i+'A'-26;
			higher[i].occ=0;
			lower[i].occ=0;
		}
			
			
		for(i=0;i<len;i++) {
			if(not_encoded[i]>='a' && not_encoded[i]<='z')
				lower[not_encoded[i]-'a'].occ++;
			else if(isalpha(not_encoded[i])) 
				lower[not_encoded[i]-'A'+26].occ++;
		}
		for(i=0;i<51;i++) 
			for(j=i+1;j<52;j++) 
				if(lower[i].occ<lower[j].occ) {
					temp=lower[i];
					lower[i]=lower[j];
					lower[j]=temp;
				}
		
		len=strlen(encoded);
		for(i=0;i<len;i++) {
			if(encoded[i]>='a' && encoded[i]<='z')
				higher[encoded[i]-'a'].occ++;
			else if(isalpha(not_encoded[i]))
				higher[encoded[i]-'A'+26].occ++;
		}
		for(i=0;i<51;i++) 
			for(j=i+1;j<52;j++) 
				if(higher[i].occ<higher[j].occ) {
					temp=higher[i];
					higher[i]=higher[j];
					higher[j]=temp;
				}

		for(i=0;;i++) {
			if(higher[i].occ==0) break;
			for(j=0;j<len;j++) {
				if(higher[i].ch==encoded[j]) 
					encoded[j]=lower[i].ch;
			}
		}

		puts(encoded);
		flag=1;
	}
return 0;
}
		
	
Last edited by smilitude on Mon Nov 28, 2005 11:39 am, edited 1 time in total.
fahim
#include <smile.h>

ayon
Experienced poster
Posts: 161
Joined: Tue Oct 25, 2005 8:38 pm
Location: buet, dhaka, bangladesh

Post by ayon » Thu Nov 03, 2005 10:48 am

I am not sure about the line !!!
=> lower.ch=i+'A-26';

what is meant by 'A-26' ?

moreover this is a multiple input problem. you have to count how many testcases...
ishtiak zaman
----------------
the world is nothing but a good program, and we are all some instances of the program

User avatar
smilitude
Experienced poster
Posts: 137
Joined: Fri Jul 01, 2005 12:21 am

Post by smilitude » Sun Nov 27, 2005 8:21 pm

Oh, thanks a lot,
thats a good bug! [ i mean thats a serious bug! :roll: you know, bug cannot be good!]

thanks...
but whats wrong with multiple input output ...?
can you give me hint??
fahim
#include <smile.h>

ayon
Experienced poster
Posts: 161
Joined: Tue Oct 25, 2005 8:38 pm
Location: buet, dhaka, bangladesh

Post by ayon » Mon Nov 28, 2005 9:03 am

The input begins with a single positive integer on a line by itself indicating the number of the cases following. say the integer is 3. then there must be 3 sets of inputs.

Code: Select all

3
                    <- empty line
abacxbacac
qqqqqrrrrssstt
                    <- empty line
abacxbacac
qqqqqrrrrssstt
                    <- empty line
abacxbacac
qqqqqrrrrssstt
EOF
Every sets must not be same, i write the same inputs only for example.

then the output must be:

Code: Select all

aaaaaccccbbbxx
                          <- empty line
aaaaaccccbbbxx
                          <- empty line
aaaaaccccbbbxx
i write my code as:

Code: Select all

	scanf("%d", &test);
	for(count = 0; count < test; ++count)
	{
		scanf(" %[^\n]", s);
		scanf(" %[^\n]", p);
      .........
      .........
   }
ishtiak zaman
----------------
the world is nothing but a good program, and we are all some instances of the program

User avatar
smilitude
Experienced poster
Posts: 137
Joined: Fri Jul 01, 2005 12:21 am

Post by smilitude » Mon Nov 28, 2005 11:38 am

i changed my code, as you told. still i got wa...
fahim
#include <smile.h>

Post Reply

Return to “Volume 4 (400-499)”