Orchid Win7 v1 <voi### [at] dev null> wrote:
> Haskell:
> foobar :: String -> [Int]
> foobar = sort . map read . words
> C#:
> public List<Int> foobar(String s)
> {
> string[] words = s.Split(' ');
> List<Int> list = new List<Int>();
> foreach (String word in words) {list.add(int.Parse(word));}
> list.Sort();
> return list;
> }
In C++ I would probably write it like:
std::vector<int> foobar(const std::string& s)
{
std::istringstream is(s);
std::vector<int> result;
int value;
while(is >> value) result.push_back(value);
std::sort(result.begin(), result.end());
return result;
}
--
- Warp
Post a reply to this message
|