Created
February 21, 2014 18:39
-
-
Save bitwiser/9140466 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Put input in a file named in.txt in the same directory as the source | |
*/ | |
#include<iostream> | |
#include<cmath> | |
#include<fstream> | |
#include<algorithm> | |
using namespace std; | |
bool isPrime(long long t){ | |
if(t==2) | |
return true; | |
int sq = sqrt(t); | |
for(long long i=2;i<sq;i++){ | |
if(t%i==0) | |
return false; | |
} | |
return true; | |
} | |
int main(){ | |
ifstream in; | |
in.open("in.txt"); | |
int init = 0,cnt=0; | |
long long prime,even,odd; | |
long long arr[10] = {0}; | |
prime = even = odd = 0; | |
long long t; | |
while(in>>t){ | |
if(t==-1) | |
break; | |
if(isPrime(t)){ | |
prime++; | |
} | |
if(t%2==0) | |
even++; | |
else | |
odd++; | |
if(!init && cnt<10){ | |
cnt++; | |
arr[0] = t; | |
sort(arr,arr+10); | |
} | |
else{ | |
if(t>arr[9]) | |
arr[0] = t; | |
sort(arr,arr+10); | |
} | |
} | |
cout<<"Top 10 numbers: \n"; | |
for(int i=0;i<10;i++){ | |
cout<<arr[i]<<" "; | |
} | |
cout<<endl; | |
cout<<"Number of Primes: "<<prime<<endl; | |
cout<<"Number of Even: "<<even<<endl; | |
cout<<"Number of Odd: "<<odd; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment