10789 - Prime Frequency

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

Moderator: Board moderators

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: WA-10789 - Prime frequency

Post by brianfry713 » Wed Jan 22, 2014 10:40 pm

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!

User avatar
uDebug
A great helper
Posts: 475
Joined: Tue Jul 24, 2012 4:23 pm

Re: 10789 - Prime Frequency

Post by uDebug » Thu Apr 03, 2014 8:20 am

Replying to follow the thread.
Check input and AC output for over 7,500 problems on uDebug!

Find us on Facebook. Follow us on Twitter.

User avatar
uDebug
A great helper
Posts: 475
Joined: Tue Jul 24, 2012 4:23 pm

Re: WA-10789 - Prime frequency

Post by uDebug » Thu Apr 03, 2014 8:32 am

Replying to follow the thread.
Check input and AC output for over 7,500 problems on uDebug!

Find us on Facebook. Follow us on Twitter.

Sherringford
New poster
Posts: 1
Joined: Fri Sep 19, 2014 4:48 pm

Re: 10789 - Prime Frequency

Post by Sherringford » Mon Sep 22, 2014 6:26 pm

figured it out later after i posted it.

cheers.

Ranit
New poster
Posts: 2
Joined: Fri May 31, 2013 8:09 pm

Re: 10789 - Prime Frequency

Post by Ranit » Fri Oct 24, 2014 4:31 pm

Try these inputs...

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

coder.tanvir
New poster
Posts: 11
Joined: Mon Mar 09, 2015 10:30 am

Re:

Post by coder.tanvir » Fri Mar 20, 2015 11:30 pm

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

Moaz
New poster
Posts: 3
Joined: Thu Apr 09, 2015 3:59 am

Re: 10789 - Prime Frequency

Post by Moaz » Mon May 18, 2015 9:58 pm

#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

Moaz
New poster
Posts: 3
Joined: Thu Apr 09, 2015 3:59 am

Re: 10789 - Prime Frequency

Post by Moaz » Mon May 18, 2015 10:02 pm

ignore the cout statement.

Nakar81
New poster
Posts: 7
Joined: Sun Sep 18, 2016 6:40 pm

Re: 10789 - Prime Frequency

Post by Nakar81 » Mon Jan 02, 2017 7:14 pm

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

Post Reply

Return to “Volume 107 (10700-10799)”