ex_prolog - WCC-Seminar/Comparative GitHub Wiki

Prolog problems -1. List

problems from https://sites.google.com/site/prologsite/prolog-problems/1

###1.01 Find the last element of a list. List は a (= [a0,a1,..., an]) として ####C++ ######配列

//int a[n+1];
a[sizeof(a)/sizeof(a[0])-1]
*(a+sizeof(a)-sizeof(a[0]))

######STL

//I used <list> this time. However, you can use <vector>, <set>, <map>, <deck>, or <array> in the same way.
//#include<list>
//std::list<int> a;
*(--a.end()) //or use *(--a.cend()) as a constant.
*a.rbegin()

//if you want to use 2-bit lists, use <bitset>.
//#include<bitset>
//std::bitset<n> a;
a[a.size()-1]

Python

a[-1]

Ruby

a[-1]

or

a.last

Haskell

last a

Lua

a[#a]

and perhaps a lot more..

⚠️ **GitHub.com Fallback** ⚠️