755 - 487--3279
Moderator: Board moderators
-
- Learning poster
- Posts: 70
- Joined: Sat Feb 05, 2005 9:38 am
- Location: Gurukul
Sorry
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.
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 ....
-
- Learning poster
- Posts: 70
- Joined: Sat Feb 05, 2005 9:38 am
- Location: Gurukul
755
Hi Tamal,
There are two mistake.
1. You print your output like this
** 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 :-
I think u still get P.E after modify this. That is upto you. Good Luck.
There are two mistake.
1. You print your output like this
But what abt this case --->printf("%3d-%4d",temp/10000,temp%10000);
printf(" %ld\n",count);
** 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 :-
2. You always print extra new line cause you a P.E.printf("%03ld-%04ld",temp/10000,temp%10000);
printf(" %ld\n",count);
I think u still get P.E after modify this. That is upto you. Good Luck.
Some Love Stories Live Forever ....
- Ali Arman Tamal
- Learning poster
- Posts: 76
- Joined: Sat Jan 15, 2005 5:04 pm
- Location: Dhaka
- Contact:
755 need a fast algrithem
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
my code looks ugly..... need help...[/code]
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;
}
}
755 [487-3279] help me
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;
}
why wa???????????
755. (487-3279). W.A.
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.
I don't know what's wrong in my code.
Below my code.
Code: Select all
code removed after A.C.
Last edited by mosaick2 on Thu Sep 28, 2006 2:39 pm, edited 1 time in total.
-
- Guru
- Posts: 1080
- Joined: Thu Dec 19, 2002 7:37 pm
You have declared the following array locally.
Which is too big to be declaed locally. Use it globally. Hope it helps.
Code: Select all
char phn[max][100];
Ami ekhono shopno dekhi...
HomePage
HomePage