755 - 487--3279

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

Moderator: Board moderators

Raj Ariyan
Learning poster
Posts: 70
Joined: Sat Feb 05, 2005 9:38 am
Location: Gurukul

Sorry

Post by Raj Ariyan »

Hi Kenneth.
I'm extreamly sorry. Actually when i copy my input file at that time something was missing. Now i edited my input and output. Sorry again.
Some Love Stories Live Forever ....
Raj Ariyan
Learning poster
Posts: 70
Joined: Sat Feb 05, 2005 9:38 am
Location: Gurukul

755

Post by Raj Ariyan »

Hi Tamal,

There are two mistake.

1. You print your output like this
printf("%3d-%4d",temp/10000,temp%10000);
printf(" %ld\n",count);
But what abt this case --->
** when temp/10000 returns 1 digit then u print only 1 not 001
output will be 001-0002 2, but ur output will be 1- 2 2
so use this :-
printf("%03ld-%04ld",temp/10000,temp%10000);
printf(" %ld\n",count);
2. You always print extra new line cause you a P.E.

I think u still get P.E after modify this. That is upto you. Good Luck.
Some Love Stories Live Forever ....
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 »

Thank you Raj Ariyan :D
I got AC :P

I really appreciated your help, I didn't thought of that problem.

Thanks :D
sunnycare
Learning poster
Posts: 74
Joined: Tue Mar 08, 2005 2:35 am
Location: China , Shanghai

755 need a fast algrithem

Post by sunnycare »

i solved the problem 755 ,but used 9.928 seconds ...

i see others use only 0.0xx seconds......

i have generated 1,000,000 random telephone number,and my prog solved it in 118.xxx seconds......so long......

my code here

Code: Select all

#include <iostream>
#include <string>
#include <map>

using namespace std;

long t[26]={2,2,2,
				3,3,3,
				4,4,4,
				5,5,5,
				6,6,6,
				7,7,7,7,
				8,8,8,
				9,9,9,9};
long table[128];

long convert(string &s)
{
	
	long n=s.length();
	long ret=0;
	long i;
	for(i=0;i<n;i++)
	{
		if(s[i]!='-')
			ret=ret*10+table[s[i]];
	}
	
	return ret;
}
void InitTable()
{
	unsigned char i;
	for(i=0;i<128;i++)
	{
		if(i>='0'&&i<='9')
			table[i]=i-'0';
		else
			if(i>='A'&&i<='Z')
				table[i]=t[i-'A'];
	}
}
void main()
{
	
	InitTable();
	
	long ncase;
	string s;
	long tel;
	long occu;
	long n;
	cin>>ncase;
	map<long,long> telmap;
	map<long,long>::iterator ptr,end;
	cout.fill('0');
	while(ncase-->=1)
	{
		cin>>n;
		telmap.clear();
		while(n-->=1)
		{
			cin>>s;
			telmap[convert(s)]++;
		}
		ptr=telmap.begin();
		end=telmap.end();
		bool dup=false;
		
		while(ptr!=end)
		{
			if(ptr->second!=1)
			{
				dup=true;
				cout.width(3);
				tel=ptr->first;
				cout<<tel/10000<<'-';
				cout.width(4);
				cout<<tel%10000<<' ';
				cout<<ptr->second<<endl;
			}
			ptr++;
		}
		if(!dup)
			cout<<"No duplicates."<<endl;
		if(ncase!=1)
			cout<<endl;
		
	}

}
my code looks ugly..... need help...[/code]
mf
Guru
Posts: 1244
Joined: Mon Feb 28, 2005 4:51 am
Location: Zürich, Switzerland
Contact:

Post by mf »

I used my own tuned implementation of quicksort and read() function to take input, and ran less than 1 second.

Try to get rid of STL, cin/cout. This will speed up your program significantly.
sunnycare
Learning poster
Posts: 74
Joined: Tue Mar 08, 2005 2:35 am
Location: China , Shanghai

Post by sunnycare »

can you mail your prog to me??

my mail:athena_kula@msn.com
kenneth
New poster
Posts: 24
Joined: Wed Mar 02, 2005 12:29 am

Post by kenneth »

I have got all output correct. Would anyone be able to provide some tricky / large input?
redbox
New poster
Posts: 1
Joined: Tue Dec 27, 2005 9:45 am

755 [487-3279] help me

Post by redbox »

Code: Select all

#include<stdio.h>
#include<stdlib.h>
#include<math.h>
   struct Map
   {
    	int key;
    	int value;
   }map[100];

  struct List
   {
    	int size;
		int left;
    	struct Map *p;
 };

struct List list={0,100,map};
///////
int insert(struct List *p,int n)
{  int j,flag=0; 
///////////////////////
	  int low,mid,high;	
	    if(p->left==0)
	   {
            p->p=(struct Map *)realloc(p->p,(p->size+100)*sizeof(map[0]));
             p->left+=10;
	   }
		////////////
	   if(p->size==0)
	  {	 //插入第一个是
		   p->p[0].key=n;
		   p->p[0].value=1;
		   p->size=1;
	        return 0;
	  }
	       low=0;
	       high=p->size-1;
	  while(low<=high)
	{
	 	mid=(low+high)/2;
		if(n==p->p[mid].key) 
		{  //有同直
			p->p[mid].value++;
			return 0;
		}
			else if(n< p->p[mid].key)
			   high=mid-1;
		else		
			
		low=mid+1;
		
	}
    
	if(n>p->p[mid].key) 
	{
		//
		p->p[mid+1].key=n;
		p->p[mid+1].value=1;
		p->size++;
	   return 0;
	}else
	{
		//
	   for(j=p->size;j>mid;j--)
	   {
	   if(p->size==0||mid==p->size) break;
	   p->p[j]=p->p[j-1];
	   }
	   p->size++;
       p->left--;
       p->p[mid].key=n;
       p->p[mid].value=1;
	   return 0;
	}
 }
//////////////////////   
   


int main()
{  
	

	const int nummap[26]={2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,7,7,7,8,8,8,9,9,9,9};
	int n,i=0,m;
	int count,flag=0;
	long temp;
	char c[100];



 	scanf("%d",&n);
	for(;i<n;i++)
	{
      scanf("%s",&c);
	  m=0;
	  temp=0;
	  count = 7;

	   while(c[m]!='\0')
	   {   
		        if(c[m]>='0'&&c[m]<='9')
                 {
                      temp+=(c[m]-'0')*(int)(pow( 10.0,--count));
                 }
                 else if(c[m]>='A'&&c[m]<='Z')
                 {
                      temp+=nummap[c[m]-'A']*(int)(pow( 10.0,--count));
                 }
                 m++;
	   }
        insert(&list,temp);
         
	}
    
	for(i=0;i<list.size;i++)
	{		
		if(list.p[i].value>1)
		{
		
             
		
			printf("%03d-%04d %d\n",list.p[i].key/10000,(list.p[i].key% 10000),list.p[i].value);
            
			flag=1;		
		}
	}
	if(flag==0)
	{
		printf("%s","No duplicates.");
	}


	return 0;
}
but is perform good in my host
why wa???????????
aakif
New poster
Posts: 1
Joined: Tue Sep 05, 2006 8:54 pm

Post by aakif »

for(i=0,j=0;input!='\0';){


if(input=='-'){
i++;
continue;
}
Aakif Hassan

Software Engineer

BrainTree Group
mosaick2
New poster
Posts: 21
Joined: Wed Mar 08, 2006 4:05 am

755. (487-3279). W.A.

Post by mosaick2 »

Could you give me a tricky sample or advice?
I don't know what's wrong in my code.
Below my code.

Code: Select all

code removed after A.C.
Actually, My mistake is not to consider MULTISET input data.
Last edited by mosaick2 on Thu Sep 28, 2006 2:39 pm, edited 1 time in total.
little joey
Guru
Posts: 1080
Joined: Thu Dec 19, 2002 7:37 pm

Post by little joey »

There are 20+ threads for this problem. Please use an existing one instead of creating a new one!
kana
New poster
Posts: 19
Joined: Mon Mar 13, 2006 6:03 pm
Location: dhaka

RE

Post by kana »

i have no idea why i'm getting Runtime Error (Signal 11) :(
is there anyone who can help me....please..... :(

Code: Select all


     removed
Last edited by kana on Tue Dec 19, 2006 9:15 pm, edited 2 times in total.
Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:

Post by Jan »

You have declared the following array locally.

Code: Select all

char phn[max][100];
Which is too big to be declaed locally. Use it globally. Hope it helps.
Ami ekhono shopno dekhi...
HomePage
kana
New poster
Posts: 19
Joined: Mon Mar 13, 2006 6:03 pm
Location: dhaka

Post by kana »

thanks jan. :D
that was a stupid mistake. :oops:
but this time i'm getting WA & i've no idea why? :-?
kana
New poster
Posts: 19
Joined: Mon Mar 13, 2006 6:03 pm
Location: dhaka

Post by kana »

there's no one to help me !!! :cry:
Post Reply

Return to “Volume 7 (700-799)”