Re: WA-10789 - Prime frequency
Posted: 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.
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
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 );
}
Code: Select all
REMOVE AFTER AC