Here is sample code I use to count words in a post ( I found it somewhere while searching something else). Put the code in functions.php (no need to write plugin)
function blog_post_wordcount() { global $page, $pages; if ( !function_exists('str_word_count') ) { return str_word_count(strip_tags($pages[$page-1])); } else { return count(explode(" ",strip_tags($pages[$page-1]))); } }
You can call blog_post_wordcount() from template. Following code will display ad only if a post has more than 100 words:
$words=blog_post_wordcount(); if ( $words >= 100 ) { show_ad(): }