码迷,mamicode.com
首页 > 其他好文 > 详细

HackerRank - "Building a Smart IDE: Programming Language Detection"

时间:2015-06-03 07:20:29      阅读:156      评论:0      收藏:0      [点我收藏+]

标签:

So fun! It connects algorithm(regex) with real world usages!

So basically speaking, C:pointer syntax, #include\scanf\typedef; Java: import\public class syntax\try-catch syntax; Python: def syntax\special print syntax.

And BTW, if you are working on regex problems with Python, this is god-sent: http://pythex.org/

import re

import io
import sys
input_stream = io.TextIOWrapper(sys.stdin.buffer, encoding=utf-8)

s = input_stream.readlines()
s = "\n".join(s)

pc = ([^/]\*[a-zA-Z]+\w*|typedef|#include|scanf)
pj = (import\s+|public\s+class|catch\s*[(].*?[)]|System\.)
pp = (print\s+[\w\"]+|[(][[][\"\s\w,]+[]][)]|def\s+[\w]+[(])

mc = re.findall(pc, s)
mj = re.findall(pj, s)
mp = re.findall(pp, s)

bc = len(mc) > 0
bj = len(mj) > 0
bp = len(mp) > 0
if bc:
    print ("C")
if bj:
    print ("Java")
if bp:
    print ("Python")

 

HackerRank - "Building a Smart IDE: Programming Language Detection"

标签:

原文地址:http://www.cnblogs.com/tonix/p/4548199.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!