10789 - Prime Frequency
Moderator: Board moderators
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: WA-10789 - Prime frequency
Doesn't match the sample I/O. Print a newline char at the end of the last line.
Check input and AC output for thousands of problems on uDebug!
-
- New poster
- Posts: 1
- Joined: Fri Sep 19, 2014 4:48 pm
Re: 10789 - Prime Frequency
figured it out later after i posted it.
cheers.
cheers.
Re: 10789 - Prime Frequency
Try these inputs...
idufjdklmvlkue342494832674921487 (Expected output: 234789dklu)
76583hjfkshgkiKJDNHFKJSkjsdnksi (Expected output: JKhijs)
iutioerniIHGFSDHuyeuiu735982347kkj (Expected output: 37Hek)
idufjdklmvlkue342494832674921487 (Expected output: 234789dklu)
76583hjfkshgkiKJDNHFKJSkjsdnksi (Expected output: JKhijs)
iutioerniIHGFSDHuyeuiu735982347kkj (Expected output: 37Hek)
-
- New poster
- Posts: 11
- Joined: Mon Mar 09, 2015 10:30 am
Re:
input
Output
Code: Select all
10
oieurfndskjbnz000000157986216nvknMANC
idufjdklmvlkue342494832674921487
76583hjfkshgkiKJDNHFKJSkjsdnksi
iutioerniIHGFSDHuyeuiu735982347kkj
nnvnvnnv
a
0
A
0001AA
BBNAaaa9
Code: Select all
Case 1: 16k
Case 2: 234789dklu
Case 3: JKhijs
Case 4: 37Hek
Case 5: nv
Case 6: empty
Case 7: empty
Case 8: empty
Case 9: 0A
Case 10: Ba
Re: 10789 - Prime Frequency
#10789 - Prime Frequency getting Run time error. I am stuck.It works fine for me.
Code: Select all
#include<iostream>
using namespace std;
#include<string>
#include <algorithm>
int prime(int*);
int compareints (const void * , const void * );
int main()
{
char num[10];
char a[26];
char A[26];
string s;
int in;
cin>>in;
int k=0;
cin.get();
while(k<in)
{
for(int i=0;i<26;i++)
{
a[i]='0';
A[i]='0';
if(i<10)
{
num[i]='0';
}
}
getline(cin,s);
for(int i=0;i<s.length();i++)
{
if(s[i]>=65&&s[i]<=90)
A[s[i]-65]++;
else if(s[i]>=97&&s[i]<=122)
a[s[i]-97]++;
else if(s[i]>=48&&s[i]<=57)
num[s[i]-48]++;
}
string f;
int *arr=new int[2001];
int size=prime(arr);
int *r=new int [size];
for(int i=0;i<size;i++)
{
r[i]=arr[i];
cout<<r[i];
}
for(int j=0;j<26;j++)
{
int n,c=0;
if(a[j]-'0'>=2)
{
int * pItem;
n=a[j]-'0';
pItem = (int*) bsearch (&n, r, 6, sizeof (int), compareints);
if(pItem)
f+=(char)j+97;
}
c=0;
if(A[j]-'0'>=2)
{
int * pItem;
n=A[j]-'0';
pItem = (int*) bsearch (&n, r, 6, sizeof (int), compareints);
if(pItem)
f+=(char)j+65;
}
c=0;
if(num[j]-'0'>=2&&j<10)
{
int * pItem;
n=num[j]-'0';
pItem = (int*) bsearch (&n, r, 6, sizeof (int), compareints);
if(pItem)
f+=(char)j+48;
}
}
sort(f.begin(),f.end());
if(f.empty())
cout<<"Case "<<++k<<": empty"<<endl;
else
cout<<"Case "<<++k<<": "<<f<<endl;
}
return 0;
}
int prime(int*arr)
{
int j=0;
for(int n=2;n<2001;n++)
{
int c=0;
for(int i=2;n>=i*i;i++)
{
if(n%i==0)
c++;
}
if(c==0)
{
arr[j++]=n;
}
}
return j;
}
int compareints (const void * a, const void * b)
{
return ( *(int*)a - *(int*)b );
}
Last edited by brianfry713 on Fri Jun 19, 2015 7:00 am, edited 1 time in total.
Reason: Added code blocks
Reason: Added code blocks
Re: 10789 - Prime Frequency
ignore the cout statement.
Re: 10789 - Prime Frequency
I have tried all sample inputs for this problem available for this topic and my program still gets WA
Update:
BigInteger isProblablePrime(1) not is equal to 100% certain
Code: Select all
REMOVE AFTER AC
BigInteger isProblablePrime(1) not is equal to 100% certain