Page 3 of 3

Re: WA-10789 - Prime frequency

Posted: Wed Jan 22, 2014 10:40 pm
by brianfry713
Doesn't match the sample I/O. Print a newline char at the end of the last line.

Re: 10789 - Prime Frequency

Posted: Thu Apr 03, 2014 8:20 am
by uDebug
Replying to follow the thread.

Re: WA-10789 - Prime frequency

Posted: Thu Apr 03, 2014 8:32 am
by uDebug
Replying to follow the thread.

Re: 10789 - Prime Frequency

Posted: Mon Sep 22, 2014 6:26 pm
by Sherringford
figured it out later after i posted it.

cheers.

Re: 10789 - Prime Frequency

Posted: Fri Oct 24, 2014 4:31 pm
by Ranit
Try these inputs...

idufjdklmvlkue342494832674921487 (Expected output: 234789dklu)
76583hjfkshgkiKJDNHFKJSkjsdnksi (Expected output: JKhijs)
iutioerniIHGFSDHuyeuiu735982347kkj (Expected output: 37Hek)

Re:

Posted: Fri Mar 20, 2015 11:30 pm
by coder.tanvir
input

Code: Select all

10
oieurfndskjbnz000000157986216nvknMANC
idufjdklmvlkue342494832674921487
76583hjfkshgkiKJDNHFKJSkjsdnksi
iutioerniIHGFSDHuyeuiu735982347kkj
nnvnvnnv
a
0
A
0001AA
BBNAaaa9
Output

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

Posted: Mon May 18, 2015 9:58 pm
by Moaz
#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 );
}

Re: 10789 - Prime Frequency

Posted: Mon May 18, 2015 10:02 pm
by Moaz
ignore the cout statement.

Re: 10789 - Prime Frequency

Posted: Mon Jan 02, 2017 7:14 pm
by Nakar81
I have tried all sample inputs for this problem available for this topic and my program still gets WA

Code: Select all

REMOVE AFTER AC
Update:

BigInteger isProblablePrime(1) not is equal to 100% certain