restructure for cmake build.
This commit is contained in:
@@ -1,18 +1,13 @@
|
||||
# CMakeList.txt : CMake project for xtfs, include source and define
|
||||
# project specific logic here.
|
||||
#
|
||||
cmake_minimum_required (VERSION 3.16)
|
||||
|
||||
|
||||
project ("primetest")
|
||||
|
||||
# Add source to this project's executable.s
|
||||
|
||||
add_executable (primetest "src/primetest.cpp")
|
||||
|
||||
set_property(TARGET primetest PROPERTY CXX_STANDARD 17)
|
||||
set_property(TARGET primetest PROPERTY CXX_STANDARD_REQUIRED ON)
|
||||
set_property(TARGET primetest PROPERTY CXX_EXTENSIONS OFF)
|
||||
|
||||
|
||||
# TODO: Add tests and install targets if needed.
|
||||
# CMakeList.txt : CMake project for xtfs, include source and define
|
||||
# project specific logic here.
|
||||
#
|
||||
cmake_minimum_required (VERSION 3.16)
|
||||
|
||||
|
||||
project (primetest VERSION 1.0 LANGUAGES CXX)
|
||||
|
||||
set_property(TARGET PROPERTY CXX_STANDARD 21)
|
||||
set_property(TARGET PROPERTY CXX_STANDARD_REQUIRED ON)
|
||||
set_property(TARGET PROPERTY CXX_EXTENSIONS OFF)
|
||||
|
||||
add_subdirectory(src)
|
||||
|
||||
8
src/CMakeLists.txt
Normal file
8
src/CMakeLists.txt
Normal file
@@ -0,0 +1,8 @@
|
||||
# CMakeList.txt
|
||||
|
||||
add_executable(primetest primetest.cpp)
|
||||
|
||||
add_subdirectory(prime)
|
||||
|
||||
|
||||
target_link_libraries( primetest PRIVATE prime )
|
||||
16
src/prime/CMakeLists.txt
Normal file
16
src/prime/CMakeLists.txt
Normal file
@@ -0,0 +1,16 @@
|
||||
# CMakeList.txt
|
||||
|
||||
add_library(prime "")
|
||||
|
||||
target_sources(prime
|
||||
PRIVATE
|
||||
${CMAKE_CURRENT_LIST_DIR}/prime.cpp
|
||||
PUBLIC
|
||||
${CMAKE_CURRENT_LIST_DIR}/prime.hpp
|
||||
)
|
||||
|
||||
target_include_directories(prime
|
||||
|
||||
PUBLIC
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
)
|
||||
17
src/prime/prime.cpp
Normal file
17
src/prime/prime.cpp
Normal file
@@ -0,0 +1,17 @@
|
||||
#include "prime.hpp"
|
||||
|
||||
int Prime::count(int n){
|
||||
int cntout = 0;
|
||||
for( int icnt = 2; ( icnt <= n ); icnt++ ){
|
||||
int ts = 0;
|
||||
for ( int it=icnt; it > 1; --it ){
|
||||
if( (icnt % it) == 0 ) {
|
||||
ts = ts + 1;
|
||||
}
|
||||
}
|
||||
if( ts==1 ){
|
||||
cntout = cntout + 1;
|
||||
}
|
||||
}
|
||||
return cntout;
|
||||
}
|
||||
9
src/prime/prime.hpp
Normal file
9
src/prime/prime.hpp
Normal file
@@ -0,0 +1,9 @@
|
||||
#ifndef PRIME_HPP
|
||||
#define PRIME_HPP
|
||||
|
||||
class Prime {
|
||||
public:
|
||||
static int count(int n);
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,27 +1,10 @@
|
||||
#include<iostream>
|
||||
#include<prime.hpp>
|
||||
|
||||
using std::cout;
|
||||
|
||||
class Solution {
|
||||
public:
|
||||
static int countPrime(int n){
|
||||
int cntout = 0;
|
||||
for( int icnt = 2; ( icnt <= n ); icnt++ ){
|
||||
int ts = 0;
|
||||
for ( int it=icnt; it > 1; --it ){
|
||||
if( (icnt % it) == 0 ) {
|
||||
ts = ts + 1;
|
||||
}
|
||||
}
|
||||
if( ts==1 ){
|
||||
cntout = cntout + 1;
|
||||
}
|
||||
}
|
||||
return cntout;
|
||||
}
|
||||
};
|
||||
using std::endl;
|
||||
|
||||
int main(int argc, char** argv){
|
||||
std::cout << Solution::countPrime(50000) << std::endl;
|
||||
std::cout << Prime::count(50000) << std::endl;
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user