10062 - Tell me the frequencies!

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

Moderator: Board moderators

dma
New poster
Posts: 8
Joined: Wed Dec 12, 2007 1:05 pm

Re: 10062 - Tell Me the Frequencies!

Post by dma »

here is my code. Could anyone give me some I/Os? thanks in advance.

Code: Select all

#include <stdio.h>
#include <stdlib.h>

#define DB_SIZE 1024
#define OUT_LEN 1024

static int _pi_cmp_(const void* l, const void* r){
        int c = **(int**)l - **(int**)r;
        if(c) return c;
        return *(int**)r - *(int**)l;
}

int main(int  argc,  char** argv){
        int c;
        int id = 0;

        while((c=getchar()) != EOF){
                int db[DB_SIZE] = {0};
                int* out[OUT_LEN] = {0};
                int len=0, i=0;

                if('\n' == c || '\r' ==c)
                        continue;
                if(0 == id)
                        id = 1;
                else
                        printf("\n");

                do{
                        if(0 == db[c])
                                out[len++] = db+c;
                        db[c]++;
                }while((c=getchar()) && c!='\n' && c!='\r');
                qsort(out, len, sizeof(int*), _pi_cmp_);
                for(i=0; i<len; i++)
                        printf("%d %d\n", out[i] - db, *out[i]);
        }
        return 0;
}

Obaida
A great helper
Posts: 380
Joined: Wed Jan 16, 2008 6:51 am
Location: (BUBT) Dhaka,Bagladesh.

Re: 10062 - Tell Me the Frequencies!

Post by Obaida »

Look at this:
your input/output:

Code: Select all

Sorry for my mistake
I was comparing with a wrong code. :oops:
Last edited by Obaida on Wed May 28, 2008 8:22 am, edited 2 times in total.
try_try_try_try_&&&_try@try.com
This may be the address of success.
dma
New poster
Posts: 8
Joined: Wed Dec 12, 2007 1:05 pm

Re: 10062 - Tell Me the Frequencies!

Post by dma »

It said that " If two characters are present the same time print the information of the ASCII character with higher ASCII value first.".
hahahaken
New poster
Posts: 26
Joined: Tue May 27, 2008 10:42 am

Re: 10062 - Tell Me the Frequencies!

Post by hahahaken »

My code also got wrong answer, why?

Code: Select all

Removed after AC
Last edited by hahahaken on Wed May 28, 2008 1:49 pm, edited 1 time in total.
Obaida
A great helper
Posts: 380
Joined: Wed Jan 16, 2008 6:51 am
Location: (BUBT) Dhaka,Bagladesh.

Re: 10062 - Tell Me the Frequencies!

Post by Obaida »

Ok,
can every one check this massage:
"A blank line should separate each set of output.", that means that we should print blank line between cases' outputs,
and the maximum number of programs who are getting WA prints blank line after each one.
:wink:
try_try_try_try_&&&_try@try.com
This may be the address of success.
hahahaken
New poster
Posts: 26
Joined: Tue May 27, 2008 10:42 am

Re: 10062 - Tell Me the Frequencies!

Post by hahahaken »

Obaida wrote:Ok,
can every one check this massage:
"A blank line should separate each set of output.", that means that we should print blank line between cases' outputs,
and the maximum number of programs who are getting WA prints blank line after each one.
:wink:
I have added a blank line after each set of output, but still wrong answer, why?

Code: Select all

Removed after AC
Last edited by hahahaken on Wed May 28, 2008 1:49 pm, edited 1 time in total.
Obaida
A great helper
Posts: 380
Joined: Wed Jan 16, 2008 6:51 am
Location: (BUBT) Dhaka,Bagladesh.

Re: 10062 - Tell Me the Frequencies!

Post by Obaida »

well replace this part of your code:

Code: Select all

while(cin >> text)
to:

Code: Select all

while(gets(text))
and the output should be like this:

Code: Select all

AAABBC
67 1 
66 2
65 3
111223
                       <<--a blank line here.
51 1
50 2
49 3
Remove your code after Accepted.
try_try_try_try_&&&_try@try.com
This may be the address of success.
hahahaken
New poster
Posts: 26
Joined: Tue May 27, 2008 10:42 am

Re: 10062 - Tell Me the Frequencies!

Post by hahahaken »

Obaida wrote:well replace this part of your code:

Code: Select all

while(cin >> text)
to:

Code: Select all

while(gets(text))
and the output should be like this:

Code: Select all

AAABBC
67 1 
66 2
65 3
111223
                       <<--a blank line here.
51 1
50 2
49 3
Remove your code after Accepted.
What's the difference between cin and gets?
What's the purpose of replacing cin by gets?
Obaida
A great helper
Posts: 380
Joined: Wed Jan 16, 2008 6:51 am
Location: (BUBT) Dhaka,Bagladesh.

Re: 10062 - Tell Me the Frequencies!

Post by Obaida »

It happens because gets() takes the enter as a null value(character).
But cin doesn't take.
So though you have done the problem well fully but it causes WA. :wink:
try_try_try_try_&&&_try@try.com
This may be the address of success.
hahahaken
New poster
Posts: 26
Joined: Tue May 27, 2008 10:42 am

Re: 10062 - Tell Me the Frequencies!

Post by hahahaken »

Obaida wrote:It happens because gets() takes the enter as a null value(character).
But cin doesn't take.
So though you have done the problem well fully but it causes WA. :wink:
Wrong answer, AGAIN!!! so sad with the program, here is the latest version, actually what's wrong with my program? I've tried to debug for many times but still not able to find out what minor mistake(s) cause wrong answer.

Code: Select all

Removed after AC
Last edited by hahahaken on Wed May 28, 2008 1:48 pm, edited 1 time in total.
Obaida
A great helper
Posts: 380
Joined: Wed Jan 16, 2008 6:51 am
Location: (BUBT) Dhaka,Bagladesh.

Re: 10062 - Tell Me the Frequencies!

Post by Obaida »

Check the output producing system I gave above and print that way.
I got accepted by editing this so why you won't get. :o
Change the line

Code: Select all

cout << endl;
into:

Code: Select all

int count =0; <<--at the starting of the program, (before while)
if(count!=0) cout << endl;
count =1;
try_try_try_try_&&&_try@try.com
This may be the address of success.
hahahaken
New poster
Posts: 26
Joined: Tue May 27, 2008 10:42 am

Re: 10062 - Tell Me the Frequencies!

Post by hahahaken »

Obaida wrote:Check the output producing system I gave above and print that way.
I got accepted by editing this so why you won't get. :o
Change the line

Code: Select all

cout << endl;
into:

Code: Select all

int count =0; <<--at the starting of the program, (before while)
if(count!=0) cout << endl;
count =1;
I follow your method to change but still got wrong answer, why?

Code: Select all

Removed after AC
Last edited by hahahaken on Wed May 28, 2008 1:48 pm, edited 1 time in total.
Obaida
A great helper
Posts: 380
Joined: Wed Jan 16, 2008 6:51 am
Location: (BUBT) Dhaka,Bagladesh.

Re: 10062 - Tell Me the Frequencies!

Post by Obaida »

This part will be just under gets()

Code: Select all

if(counter != 0)
        cout << endl;
        counter = 1;
try_try_try_try_&&&_try@try.com
This may be the address of success.
hahahaken
New poster
Posts: 26
Joined: Tue May 27, 2008 10:42 am

Re: 10062 - Tell Me the Frequencies!

Post by hahahaken »

Obaida wrote:This part will be just under gets()

Code: Select all

if(counter != 0)
        cout << endl;
        counter = 1;
I finally figure out what's wrong with the blank line, those blank lines make my submission WA AGAIN and AGAIN, I finally got accepted, thank a lot
P.S. The correct ouput should be like this

Code: Select all

AAABBC
67 1
66 2
65 3
122333
            <-- blank line
49 1
50 2
51 3
A A A
           <-- blank line
32 2       <-- spaces between the "A"s are also counted
65 3       <-- last line of output
|          <-- cursor here, no blank line after the last line of output
maruf
New poster
Posts: 17
Joined: Sat May 24, 2008 6:00 pm

Re: 10062 - Tell Me the Frequencies!

Post by maruf »

where is the bug???? :roll:

Code: Select all


#include<stdio.h>
#include<string.h>
int main()
{
    char x[5000];
	char a[5000];
	int b[5000];
	int i,j,cs;
	int c=1,p,pass,t,m;
     
     while(gets(x))
	{
		if(cs==1)
		printf("\n");
	    cs=1;
    p=strlen(x);
	int k=0;
	for(i=0;i<p;i++)
      {
		c=1;
	  if(x[i]=='\0')
		  continue;
	  for(j=i+1;j<p;j++)
	  {
		  if(x[i]==x[j])
		  {
			  c++;
		      x[j]='\0';
		  }
	  }
	  if(x[i]!='\0')
      b[k]=c;
      a[k++]=x[i];
	  
	}
	for(pass=1;pass<k;pass++)
	{
		for(j=0;j<k-1;j++)
		{
			if(b[j]>b[j+1])
			{
				t=a[j];
				m=b[j];
			    a[j]=a[j+1];
				b[j]=b[j+1];
			    a[j+1]=t;
				b[j+1]=m;
			}
			
		}
	}
	
	for(pass=1;pass<k;pass++)
	{
	  for(j=0;j<k;j++)
	  {
	    if(b[j]==b[j+1])
		{
		  if(a[j]<a[j+1])
		     {
			   t=a[j];
			   a[j]=a[j+1];
			   a[j+1]=t;
			 }
		}
	  }
	}
	
	
	for(p=0;p<k;p++)
	{
		printf("%d %d\n",a[p],b[p]);
	}

	
	}
    return 0;

}
lives for eternity......
Post Reply

Return to “Volume 100 (10000-10099)”