755 - 487-3279

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

Moderator: Board moderators

755 - 487-3279

Postby C8H10N4O2 » Tue Jun 11, 2002 5:07 pm

Can someone tell me why this WAs?
[cpp]
#include <stdio.h>
#include <map>
#include <string>
#include <algorithm>

using namespace std;

void main()
{
string Translation="ABCDEFGHIJKLMNOPRSTUVWXY";
map<string,int> Directory;
map<string,int>::iterator DirectoryIT;
char B[1000];
char C[10];
int i,j,N,k,O;
O=0;
scanf("%*d");
while(scanf("%d",&N)!=EOF)
{
if(O++)
{
printf("\n");
}
Directory.clear();
for(i=0;i<N;i++)
{
scanf("%s",B);
k=0;
for(j=0;j<strlen(B);j++)
{
if(isdigit(B[j]))
{
C[k++]=B[j];
}
if(isalpha(B[j]))
{
C[k++]=(find(Translation.begin(),Translation.end(),B[j])-Translation.begin())/3+2+'0';
}
}
C[k++]='\0';
Directory[C]++;
}
k=0;
for(DirectoryIT=Directory.begin();DirectoryIT!=Directory.end();DirectoryIT++)
{
if((*DirectoryIT).second>1)
{
k++;
printf("%s-%s %d\n",(*DirectoryIT).first.substr(0,3).c_str(),(*DirectoryIT).first.substr(3,4).c_str(),(*DirectoryIT).second);
}
}
if(k==0)
{
printf("No duplicates.\n");
}
}
}[/cpp]
C8H10N4O2
Experienced poster
 
Posts: 137
Joined: Wed Feb 27, 2002 2:00 am
Location: Pasadena, CA

755

Postby Sherman MXF » Wed Jun 19, 2002 10:32 am

I couldn't understand why i got RE(SIGSEGV)!
Is there anything i have not mentioned?

:( :( :(
Sherman MXF
New poster
 
Posts: 14
Joined: Sun May 26, 2002 1:54 pm
Location: China

Postby Stefan Pochmann » Wed Jun 19, 2002 10:41 am

Anything you haven't mentioned *where*? Do you mean you've asked about this problem before? I couldn't find it in your past posts...
Stefan Pochmann
A great helper
 
Posts: 284
Joined: Thu Feb 28, 2002 2:00 am
Location: Germany

Postby Sherman MXF » Thu Jun 20, 2002 2:08 am

Sorry, my dictionary software did not work well... I use it to translate Chinese into English. :roll:

I mean that I couldn't find anything wrong in my program, it works well on my computer, even if the input contains 100,000 lines. But it got RE(SIGSEGV) here. Why?
Sherman MXF
New poster
 
Posts: 14
Joined: Sun May 26, 2002 1:54 pm
Location: China

Postby Stefan Pochmann » Thu Jun 20, 2002 6:15 am

Do you handle multiple input correctly?
Stefan Pochmann
A great helper
 
Posts: 284
Joined: Thu Feb 28, 2002 2:00 am
Location: Germany

Postby Sherman MXF » Thu Jun 20, 2002 8:35 am

I've already processed the multiple input.
My program get RE after about 14s
Sherman MXF
New poster
 
Posts: 14
Joined: Sun May 26, 2002 1:54 pm
Location: China

Postby 10153EN » Thu Jun 20, 2002 8:46 am

Try to allocate a larger size of array~
10153EN
Experienced poster
 
Posts: 148
Joined: Sun Jan 06, 2002 2:00 am
Location: Hong Kong

Postby Sherman MXF » Fri Jun 21, 2002 2:54 am

I use pointer to make a list.
I've modified my program. This time it got RE(SIGSEGV) after 17.41s at testpoint 10.
Sherman MXF
New poster
 
Posts: 14
Joined: Sun May 26, 2002 1:54 pm
Location: China

755 why p.e.?

Postby zsacul » Sat Aug 17, 2002 8:18 pm

Why I have presentation error, I think I handle multiple input correctly...


[cpp]
#include <stdio.h>
#include <string.h>

int tel[100000];

int ile[200000];
int ileI[200000];

int odp[50001];
int odp2[50001];

void QSort(int left, int right)
{
:wink:
}

bool getC(char z,int &c)
{
if ((z>='0')&&(z<='9')) { c = z-'0'; return true; }

switch (z)
{
case 'A':
case 'B':
case 'C': c = 2; return true;
case 'D':
case 'E':
case 'F': c = 3; return true;
case 'G':
case 'H':
case 'I': c = 4; return true;
case 'J':
case 'K':
case 'L': c = 5; return true;
case 'M':
case 'N':
case 'O': c = 6; return true;
case 'P':
case 'R':
case 'S': c = 7; return true;
case 'T':
case 'U':
case 'V': c = 8; return true;
case 'W':
case 'X':
case 'Y': c = 9; return true;
}

return false;
}

int getInx(int nr)
{
:wink:
}

int getNum(char *txt)
{
int res = 0,c,i;
int nLen = strlen(txt);

for (i=0;i<nLen;i++)
if (getC(txt[i],c))
{
res*=10;
res+=c;
}

return res;
}

void printOdp(int a,int b)
{
char c[8];
int i;
for (i=0;i<8;i++)
{
c[i] = a%10;
a/=10;
}

for (i=6;i>=4;i--) printf("%c",'0'+c[i]);
printf("-");
for (i=3;i>=0;i--) printf("%c",'0'+c[i]);

printf(" %ld\n",b);
}

void main()
{
int i;
int n;
char tels[200];

bool bFirst = true;

while (scanf("%d\n",&n)!=EOF)
{
if (!bFirst) printf("\n");
bFirst = false;

for (i=0;i<200000;i++)
{
ile[i] =0;
ileI[i]=-1;
}

for (i=0;i<n;i++)
{
scanf("%s\n",tels);
tel[i] = getNum(tels);
}

for (i=0;i<n;i++)
{
int num = tel[i];
int inx = getInx(num);
ileI[inx] = num;
ile[inx]++;
}

int ileOdp = 0;
for (i=0;i<n;i++)
{
int num = tel[i];
int inx = getInx(num);

if (ile[inx]>1)
{
odp[ileOdp] = num;
odp2[ileOdp++] = ile[inx];
}
ile[inx] = 0;
}

if (ileOdp==0)
{
printf("No duplicates.\n");
}
else
{
QSort(0,ileOdp-1);
for (i=0;i<ileOdp;i++) printOdp(odp[i],odp2[i]);
}
}
}

[/cpp]
zsacul
New poster
 
Posts: 7
Joined: Sat Aug 17, 2002 8:11 pm
Location: Poland

Postby zsacul » Thu Aug 29, 2002 12:57 am

Finaly I've got A.C, I handled multiple input incorectly... :cry:
zsacul
New poster
 
Posts: 7
Joined: Sat Aug 17, 2002 8:11 pm
Location: Poland

755 Need help

Postby Revenger » Mon Sep 16, 2002 7:52 pm

I've just wonder why this code gets WA :(
It's only simple merge sort

[pascal]Program p755;

Const MaxN = 110000;
LDig : Array['A'..'Z']of Integer = ( 2, 2, 2,
3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6,
7, 0, 7, 7, 8, 8, 8, 9, 9, 9, 0 );

Var T,tt,i : Integer;
p,j,k,c : Integer;
Amount : Array[1..MaxN]of Integer;
Tmp : Array[0..MaxN]of Integer;

Procedure ReadPhone(Var Ph : Integer);
Var S : String;
Ch : Char;
i : Integer;
begin
S:='';
While (Not Eoln) And (Not Eof) do begin
Read(Ch);
if Ch in ['0'..'9'] then S:=S+Ch;
if (Ch in ['A'..'Z']) And (Ch<>'Q') And (Ch<>'Z') then S:=S+Ch;
end;
Readln;
Ph:=0;
for i:=1 to length(S) do
if S[i] in ['A'..'Z'] then
Ph:=Ph*10+LDig[S[i]]
else
Ph:=Ph*10+Ord(S[i])-Ord('0');
end;

Procedure WritePhone(Ph,c : Integer);
Var i : Integer;
S : String;
begin
j:=j+1;
Str(Ph,S);
While length(S)<7 do S:='0'+S;
for i:=1 to 3 do Write(S[i]);
Write('-');
for i:=4 to 7 do Write(S[i]);
Writeln(' ',c);
end;

Procedure Swap(Var A1,A2 : integer);
Var t : integer;
begin
t:=A1;
A1:=A2;
A2:=t;
end;

Procedure Merge(left,middle,rigth : integer);
Var Ileft,Irigth,Cur,i : integer;
begin
Ileft:=left;
Irigth:=middle+1;
Cur:=0;
While True do begin
Cur:=Cur+1;
if Amount[Ileft]<Amount[Irigth] then begin
Tmp[Cur]:=Amount[Ileft];
Ileft:=Ileft+1;
end else begin
Tmp[Cur]:=Amount[Irigth];
Irigth:=Irigth+1;
end;
if Ileft=middle+1 then begin
for i:=Irigth to rigth do begin
Cur:=Cur+1;
Tmp[Cur]:=Amount[i];
end;
break;
end;
if Irigth=rigth+1 then begin
for i:=Ileft to middle do begin
Cur:=Cur+1;
Tmp[Cur]:=Amount[i];
end;
break;
end;
end;
for i:=1 to rigth-left+1 do
Amount[left+i-1]:=Tmp[i];
end;

Procedure MergeSort(left,rigth : integer);
Var middle : integer;
begin
if rigth-left<=0 then exit;
if rigth-left=1 then begin
if Amount[left]>Amount[rigth] then
Swap(Amount[left],Amount[rigth]);
exit;
end;
middle:=(left + rigth) div 2;
MergeSort(left,middle);
MergeSort(middle+1,rigth);
Merge(left,middle,rigth);
end;

begin
Readln(T);
for tt:=1 to T do begin
Readln;
Readln(k);
for i:=1 to k do begin
ReadPhone(j);
Amount[i]:=j;
end;
j:=0;
MergeSort(1,k);
p:=-1;
c:=0;
for i:=1 to k do
if Amount[i]=p then begin
c:=c+1;
end else begin
if c>1 then WritePhone(p,c);
c:=1;
p:=Amount[i];
end;
if j=0 then Writeln('No duplicates.');
Writeln;
end;
end.[/pascal]
Revenger
Experienced poster
 
Posts: 132
Joined: Sun Apr 14, 2002 12:27 pm
Location: Russia

755 - keep getting WA! whats wrong with this?

Postby loststar » Mon Sep 30, 2002 12:25 am

I've submited the this answer to the 755 , and i keep getting WA. Each time i find a new bug , but i simply cant find anymore...
What's wrong with this code?

[cpp]
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <hash_map>
#include <vector>
#include <iostream>

int main()
{
/* hash_map<const char*, int, hash<const char*>, eqstr> months;*/
hash_map<int, int> addresses;
hash_map<int, int> keymaps;
int n, c,i, cut, j, k;
long num;
char number[1025];
vector <long> v;
int notnull=0;
int number_of_lines, number_of_problems;
int dups=0;

keymaps['A'] = 2;
keymaps['B'] = 2;
keymaps['C'] = 2;

keymaps['D'] = 3;
keymaps['E'] = 3;
keymaps['F'] = 3;

keymaps['G'] = 4;
keymaps['H'] = 4;
keymaps['I'] = 4;

keymaps['J'] = 5;
keymaps['K'] = 5;
keymaps['L'] = 5;

keymaps['M'] = 6;
keymaps['N'] = 6;
keymaps['O'] = 6;

keymaps['P'] = 7;
keymaps['R'] = 7;
keymaps['S'] = 7;

keymaps['T'] = 8;
keymaps['U'] = 8;
keymaps['V'] = 8;

keymaps['W'] = 9;
keymaps['X'] = 9;
keymaps['Y'] = 9;

scanf("%d\n", &number_of_problems);

for (k=0 ; k<number_of_problems; k++)
{
notnull =0;
dups =0;
v.clear();
addresses.clear();
scanf("%d\n", &number_of_lines);


for(j =0 ; j<number_of_lines; j++)
{
scanf("%[^\n]", number);
getchar();
c = 1;
n = strlen(number);
num = 0;
for (i=0; i<n ;i++)
{
if ((number[i]>='0') && (number[i] <='9'))
{
num = num*c;
num = num + (number[i]-'0');
c = 10;
}
else if ((number[i]>='A') && (number[i] <='Z'))
{
num = num*c;
num = num + (keymaps[(int)number[i]]);
c = 10;
}
}
notnull = 1 ;
addresses[num]++;
if(addresses[num] == 1)
v.push_back(num);
}
if ( notnull ) {
sort( v.begin(), v.end() );
for (vector<long>::const_iterator viter=v.begin(); viter!=v.end(); ++viter)
{
if (addresses[*viter] >1)
{
cut = *viter/10000;
cout << cut << "-" << *viter-cut*10000 <<" " << addresses[*viter] << endl;
dups++;
}
}
}
if (dups == 0)
cout << "No duplicates." << endl;

cout << endl;
}

return 0;
}
[/cpp]
loststar
New poster
 
Posts: 1
Joined: Mon Sep 30, 2002 12:04 am

Postby Ivor » Mon Sep 30, 2002 8:35 am

Are you sure you can handle leading zeros? i.e numbers like 000-0593.

Ivor
There is a theory which states that if ever anyone discovers exactly what the Universe is for and why it is here, it will instantly disappear and be replaced by something even more bizarre and inexplicable.
Ivor
Experienced poster
 
Posts: 147
Joined: Wed Dec 26, 2001 2:00 am
Location: Tallinn, Estonia

Postby ei01036 » Thu Jan 30, 2003 4:32 pm

i've been having the same problem... my program handles correctly multiple inputs and leading zeros...

please help
ei01036
New poster
 
Posts: 12
Joined: Wed Jan 15, 2003 1:13 am

Postby Ghost77 dimen » Sat Aug 16, 2003 1:30 pm

Hello, revenger. 8)

Try this sample input.

1

12
0-0-0-0-0-0-0
00-0-0-0-0-0
000-0-0-0-0
0000-0-0-0
00000-0-0
000000-0
001-----------------------------------0000
001-------------------------------------------------0000
0---------00000--------1
0000--------------------------------001
---------------------------------1000000
1000--------000----------------------------------------

The output should be as follows
<no blank line>
000-0000 6
000-0001 2
001-0000 2
100-0000 2
<no blank line>

Good luck.
User avatar
Ghost77 dimen
Learning poster
 
Posts: 67
Joined: Sun Sep 22, 2002 5:40 am
Location: Taiwan

Next

Return to Volume VII

Who is online

Users browsing this forum: No registered users and 0 guests