Page 12 of 16

Re: 10062 - Tell Me the Frequencies!

Posted: Sun May 25, 2008 9:39 am
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;
}


Re: 10062 - Tell Me the Frequencies!

Posted: Sun May 25, 2008 10:47 am
by Obaida
Look at this:
your input/output:

Code: Select all

Sorry for my mistake
I was comparing with a wrong code. :oops:

Re: 10062 - Tell Me the Frequencies!

Posted: Tue May 27, 2008 11:32 am
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.".

Re: 10062 - Tell Me the Frequencies!

Posted: Tue May 27, 2008 2:07 pm
by hahahaken
My code also got wrong answer, why?

Code: Select all

Removed after AC

Re: 10062 - Tell Me the Frequencies!

Posted: Wed May 28, 2008 8:19 am
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:

Re: 10062 - Tell Me the Frequencies!

Posted: Wed May 28, 2008 8:43 am
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

Re: 10062 - Tell Me the Frequencies!

Posted: Wed May 28, 2008 9:31 am
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.

Re: 10062 - Tell Me the Frequencies!

Posted: Wed May 28, 2008 9:43 am
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?

Re: 10062 - Tell Me the Frequencies!

Posted: Wed May 28, 2008 10:58 am
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:

Re: 10062 - Tell Me the Frequencies!

Posted: Wed May 28, 2008 11:38 am
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

Re: 10062 - Tell Me the Frequencies!

Posted: Wed May 28, 2008 12:31 pm
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;

Re: 10062 - Tell Me the Frequencies!

Posted: Wed May 28, 2008 1:12 pm
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

Re: 10062 - Tell Me the Frequencies!

Posted: Wed May 28, 2008 1:43 pm
by Obaida
This part will be just under gets()

Code: Select all

if(counter != 0)
        cout << endl;
        counter = 1;

Re: 10062 - Tell Me the Frequencies!

Posted: Wed May 28, 2008 1:50 pm
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

Re: 10062 - Tell Me the Frequencies!

Posted: Sun Aug 03, 2008 1:37 pm
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;

}