Try the cows. B Language: Find palindrome number

Source: Internet
Author: User

Environment:

cpu:i5-4200

mem:4g

Os:64bit--Windows & Ubuntu (trusty)

C language

1#include <stdio.h>2#include <stdlib.h>3#include <time.h>4 5 BOOLIshuiwen (intN) {6     intsn =0;7sn =N;8     intTN =0;9      while(SN! =0) {TenTN = TN *Ten+ sn%Ten; Onesn = SN/Ten; A     } -     if(TN = =N) -         return true; the     return false; - } -  - inthw1 () { +     inttx =0; -     intx =0; +      for(x =0; X <=10000000; X + +) { A         if(Ishuiwen (x) = =true) atTX + +; -     } -     returnTX; - } -  - voidrunhw1 () { in clock_t start, finish; -     Doubleduration; toStart =clock (); +     intTotal =hw1 (); -finish =clock (); theDuration = (Double) (Finish-start)/clocks_per_sec; *printf"Total =%d,%f seconds\n", total, duration); $ }Panax Notoginseng intMain () { - runhw1 (); the     return 0; +}

Results:

[Email protected]:/mnt/c/users/whsse/ubuntu$ g++T2.c[email protected]-sa2e7tl:/mnt/c/users/whsse/ubuntu$./A.outtotal=10999,0.484375Seconds[email protected]-sa2e7tl:/mnt/c/users/whsse/ubuntu$./A.outtotal=10999,0.437500Seconds[email protected]-sa2e7tl:/mnt/c/users/whsse/ubuntu$./A.outtotal=10999,0.437500Seconds[email protected]-sa2e7tl:/mnt/c/users/whsse/ubuntu$ g++-O3 T2.c[email protected]-sa2e7tl:/mnt/c/users/whsse/ubuntu$./A.outtotal=10999,0.156250Seconds[email protected]-sa2e7tl:/mnt/c/users/whsse/ubuntu$./A.outtotal=10999,0.156250Seconds[email protected]-sa2e7tl:/mnt/c/users/whsse/ubuntu$./A.outtotal=10999,0.140625Seconds

Go language:

1 Package Main2 3 Import (4     "FMT"5     " Time"6 )7 8Func HW (numint)BOOL {9SOURCE, Tnum: = num,0Ten      forNum! =0 { OneTnum = tnum*Ten+ num%Ten Anum = num/Ten -     } -     returnTnum = =Source the } - func hw () { -T1: =Time . Now () -All, total: =10000000,0 +      forN: =0; n <= all; n++ { -         ifHW (n) { +total++ A         } at     } -Fmt. Printf (' total:%d time:%f ', total, time. Now (). Sub (T1). Seconds ()) - } -  - Func Main () { - HW () in}

Results:

C:\users\whsse\ubuntu>Go build go_t.goc:\users\whsse\ubuntu>go_t.exetotal:10999 Time:0.216019C:\Users\whsse\ubuntu>go_t.exetotal:10999time :0.217023C:\Users\whsse\ubuntu>go_t.exetotal:10999time :0.214510

Ponyc language

1Use"Collections"2Use" Time"3 4 actor Main5 NewCreate (env:env) =6 7 varAll:u32 =100000008 varTotal:u32 =09 Ten varT1 =Time.now () One  forIinchRANGE[U32] (0, all) Do A     ifHW (i) then total = Total +1End - End -  the vart2 =Time.now () - vart = Time.wall_to_nanos (T2)-Time.wall_to_nanos (t1) -  -Env. out. print (total.string()) +Env. out. Print ((t/1000000).string()) -  +  AFun HW (num:u32): Bool = at     varNum'= num -     varTnum:u32 =0 -      whileNum'! = 0 do -Tnum = (Tnum *Ten) + (num'%) -Num'= num'/Ten - End in     ifTnum = = num Thenreturn true /*Else False*/End -     false

Results:

[email protected]:/mnt/c/users/whsse/ubuntu/pony_t$./pony_t10999143[email Protected]-sa2e7tl:/mnt/c/users/whsse/ubuntu/pony_t$./pony_t10999149[email Protected]-sa2e7tl:/mnt/c/users/whsse/ubuntu/pony_t$./pony_t10999[ Email protected]-sa2e7tl:/mnt/c/users/whsse/ubuntu/pony_t$./pony_t10999144 

Original: http://my.oschina.net/raddleoj/blog/510932

Organized in 2016-07-10

Try the cows. B Language: Find palindrome number

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.