Page 5 of 8
Sorry
Posted: Tue Mar 08, 2005 2:55 pm
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.
755
Posted: Tue Mar 08, 2005 3:25 pm
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.
Posted: Fri Mar 18, 2005 5:17 pm
by Ali Arman Tamal
Thank you Raj Ariyan
I got AC
I really appreciated your help, I didn't thought of that problem.
Thanks
755 need a fast algrithem
Posted: Mon Apr 04, 2005 4:20 am
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]
Posted: Mon Apr 04, 2005 7:52 am
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.
Posted: Tue Apr 05, 2005 3:30 am
by sunnycare
can you mail your prog to me??
my mail:
athena_kula@msn.com
Posted: Tue May 10, 2005 8:30 am
by kenneth
I have got all output correct. Would anyone be able to provide some tricky / large input?
755 [487-3279] help me
Posted: Tue Dec 27, 2005 9:52 am
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???????????
Posted: Sun Sep 10, 2006 1:42 am
by aakif
for(i=0,j=0;input!='\0';){
if(input=='-'){
i++;
continue;
}
755. (487-3279). W.A.
Posted: Wed Sep 27, 2006 12:14 pm
by mosaick2
Could you give me a tricky sample or advice?
I don't know what's wrong in my code.
Below my code.
Actually, My mistake is not to consider MULTISET input data.
Posted: Wed Sep 27, 2006 12:54 pm
by little joey
There are 20+ threads for this problem. Please use an existing one instead of creating a new one!
RE
Posted: Sat Dec 09, 2006 10:32 pm
by kana
i have no idea why i'm getting Runtime Error (Signal 11)
is there anyone who can help me....please.....
Posted: Sun Dec 10, 2006 6:16 am
by Jan
You have declared the following array locally.
Which is too big to be declaed locally. Use it globally. Hope it helps.
Posted: Sun Dec 10, 2006 8:25 pm
by kana
thanks jan.
that was a stupid mistake.
but this time i'm getting WA & i've no idea why?
Posted: Mon Dec 18, 2006 9:43 pm
by kana
there's no one to help me !!!