WeixiangYan/CodeTransOcean huggingface dataset:
Task: Search a list

C: #include <stdio.h>
#include <string.h>

const char *haystack[] = {
  "Zig", "Zag", "Wally", "Ronald", "Bush", "Krusty", "Charlie",
  "Bush", "Boz", "Zag", NULL
};

int search_needle(const char *needle, const char **hs)
{
  int i = 0;
  while( hs[i] != NULL ) {
    if ( strcmp(hs[i], needle) == 0 ) return i;
    i++;
  }
  return -1;
}

int search_last_needle(const char *needle, const char **hs)
{
  int i, last=0;
  i = last = search_needle(needle, hs);
  if ( last < 0 ) return -1;
  while( hs[++i] != NULL ) {
    if ( strcmp(needle, hs[i]) == 0 ) {
      last = i;
    }
  }
  return last;
}

int main()
{
  printf("Bush is at %d\n", search_needle("Bush", haystack));
  if ( search_needle("Washington", haystack) == -1 )
    printf("Washington is not in the haystack\n");
  printf("First index for Zag: %d\n", search_needle("Zag", haystack));
  printf("Last index for Zag: %d\n", search_last_needle("Zag", haystack));
  return 0;
}











Ada: with Ada.Strings.Unbounded;  use Ada.Strings.Unbounded;
with Ada.Text_IO;            use Ada.Text_IO;

procedure Test_List_Index is
   Not_In : exception;
   
   type List is array (Positive range <>) of Unbounded_String;
   
   function Index (Haystack : List; Needle : String) return Positive is
   begin
      for Index in Haystack'Range loop
         if Haystack (Index) = Needle then
            return Index;
         end if;
      end loop;
      raise Not_In;
   end Index;

      
   function "+" (X, Y : String) return List is
   begin
      return (1 => To_Unbounded_String (X), 2 => To_Unbounded_String (Y));
   end "+";
   
   function "+" (X : List; Y : String) return List is
   begin
      return X & (1 => To_Unbounded_String (Y));
   end "+";
   
   Haystack : List := "Zig"+"Zag"+"Wally"+"Ronald"+"Bush"+"Krusty"+"Charlie"+"Bush"+"Bozo";

   procedure Check (Needle : String) is
   begin
      Put (Needle);
      Put_Line ("at" & Positive'Image (Index (Haystack, Needle)));
   exception
      when Not_In => Put_Line (" is not in");
   end Check;
begin
   Check ("Washington");
   Check ("Bush");
end Test_List_Index;
Task: Search a list




Go: package main

var haystack = []string{"Zig", "Zag", "Wally", "Ronald", "Bush", "Krusty",
    "Charlie", "Bush", "Bozo", "Zag", "mouse", "hat", "cup", "deodorant",
    "television", "soap", "methamphetamine", "severed cat heads", "foo",
    "bar", "baz", "quux", "quuux", "quuuux", "bazola", "ztesch", "foo",
    "bar", "thud", "grunt", "foo", "bar", "bletch", "foo", "bar", "fum",
    "fred", "jim", "sheila", "barney", "flarp", "zxc", "spqr", ";wombat",
    "shme", "foo", "bar", "baz", "bongo", "spam", "eggs", "snork", "foo",
    "bar", "zot", "blarg", "wibble", "toto", "titi", "tata", "tutu", "pippo",
    "pluto", "paperino", "aap", "noot", "mies", "oogle", "foogle", "boogle",
    "zork", "gork", "bork", "sodium", "phosphorous", "californium",
    "copernicium", "gold", "thallium", "carbon", "silver", "gold", "copper",
    "helium", "sulfur"}








Ada: with Ada.Strings.Unbounded;  use Ada.Strings.Unbounded;
with Ada.Text_IO;            use Ada.Text_IO;

procedure Test_List_Index is
   Not_In : exception;
   
   type List is array (Positive range <>) of Unbounded_String;
   
   function Index (Haystack : List; Needle : String) return Positive is
   begin
      for Index in Haystack'Range loop
         if Haystack (Index) = Needle then
            return Index;
         end if;
      end loop;
      raise Not_In;
   end Index;

      
   function "+" (X, Y : String) return List is
   begin
      return (1 => To_Unbounded_String (X), 2 => To_Unbounded_String (Y));
   end "+";
   
   function "+" (X : List; Y : String) return List is
   begin
      return X & (1 => To_Unbounded_String (Y));
   end "+";
   
   Haystack : List := "Zig"+"Zag"+"Wally"+"Ronald"+"Bush"+"Krusty"+"Charlie"+"Bush"+"Bozo";

   procedure Check (Needle : String) is
   begin
      Put (Needle);
      Put_Line ("at" & Positive'Image (Index (Haystack, Needle)));
   exception
      when Not_In => Put_Line (" is not in");
   end Check;
begin
   Check ("Washington");
   Check ("Bush");
end Test_List_Index;
Task: Search a list





Java: import java.util.List;
import java.util.Arrays;

List<String> haystack = Arrays.asList("Zig","Zag","Wally","Ronald","Bush","Krusty","Charlie","Bush","Bozo");

for (String needle : new String[]{"Washington","Bush"}) {
    int index = haystack.indexOf(needle);
    if (index < 0)
        System.out.println(needle + " is not in haystack");
    else
        System.out.println(index + " " + needle);
}







Ada: with Ada.Strings.Unbounded;  use Ada.Strings.Unbounded;
with Ada.Text_IO;            use Ada.Text_IO;

procedure Test_List_Index is
   Not_In : exception;
   
   type List is array (Positive range <>) of Unbounded_String;
   
   function Index (Haystack : List; Needle : String) return Positive is
   begin
      for Index in Haystack'Range loop
         if Haystack (Index) = Needle then
            return Index;
         end if;
      end loop;
      raise Not_In;
   end Index;

      
   function "+" (X, Y : String) return List is
   begin
      return (1 => To_Unbounded_String (X), 2 => To_Unbounded_String (Y));
   end "+";
   
   function "+" (X : List; Y : String) return List is
   begin
      return X & (1 => To_Unbounded_String (Y));
   end "+";
   
   Haystack : List := "Zig"+"Zag"+"Wally"+"Ronald"+"Bush"+"Krusty"+"Charlie"+"Bush"+"Bozo";

   procedure Check (Needle : String) is
   begin
      Put (Needle);
      Put_Line ("at" & Positive'Image (Index (Haystack, Needle)));
   exception
      when Not_In => Put_Line (" is not in");
   end Check;
begin
   Check ("Washington");
   Check ("Bush");
end Test_List_Index;
Task: Search a list







Python: haystack=["Zig","Zag","Wally","Ronald","Bush","Krusty","Charlie","Bush","Bozo"]

for needle in ("Washington","Bush"):
  try:
    print haystack.index(needle), needle
  except ValueError, value_error:
    print needle,"is not in haystack"





Ada: with Ada.Strings.Unbounded;  use Ada.Strings.Unbounded;
with Ada.Text_IO;            use Ada.Text_IO;

procedure Test_List_Index is
   Not_In : exception;
   
   type List is array (Positive range <>) of Unbounded_String;
   
   function Index (Haystack : List; Needle : String) return Positive is
   begin
      for Index in Haystack'Range loop
         if Haystack (Index) = Needle then
            return Index;
         end if;
      end loop;
      raise Not_In;
   end Index;

      
   function "+" (X, Y : String) return List is
   begin
      return (1 => To_Unbounded_String (X), 2 => To_Unbounded_String (Y));
   end "+";
   
   function "+" (X : List; Y : String) return List is
   begin
      return X & (1 => To_Unbounded_String (Y));
   end "+";
   
   Haystack : List := "Zig"+"Zag"+"Wally"+"Ronald"+"Bush"+"Krusty"+"Charlie"+"Bush"+"Bozo";

   procedure Check (Needle : String) is
   begin
      Put (Needle);
      Put_Line ("at" & Positive'Image (Index (Haystack, Needle)));
   exception
      when Not_In => Put_Line (" is not in");
   end Check;
begin
   Check ("Washington");
   Check ("Bush");
end Test_List_Index;
Task: Search a list








VB: Function IsInArray(stringToBeFound As Variant, arr As Variant, _
    Optional start As Integer = 1, Optional reverse As Boolean = False) As Long

    Dim i As Long, lo As Long, hi As Long, stp As Long
    
    IsInArray = -1
    If reverse Then
        lo = UBound(arr): hi = start: stp = -1
    Else
        lo = start: hi = UBound(arr): stp = 1
    End If
    For i = lo To hi Step stp 
        If StrComp(stringToBeFound, arr(i), vbTextCompare) = 0 Then
            IsInArray = i
            Exit For
        End If
    Next i
End Function
Public Sub search_a_list()
    Dim haystack() As Variant, needles() As Variant
    haystack = [{"Zig","Zag","Wally","Ronald","Bush","Krusty","Charlie","Bush","Bozo"}]
    needles = [{"Washington","Bush"}]
    For i = 1 To 2
        If IsInArray(needles(i), haystack) = -1 Then
            Debug.Print needles(i); " not found in haystack."
        Else
            Debug.Print needles(i); " is at position "; CStr(IsInArray(needles(i), haystack)); ".";
            Debug.Print " And last position is ";
            Debug.Print CStr(IsInArray(needles(i), haystack, 1, True)); "."
        End If
    Next i
End Sub




Ada: with Ada.Strings.Unbounded;  use Ada.Strings.Unbounded;
with Ada.Text_IO;            use Ada.Text_IO;

procedure Test_List_Index is
   Not_In : exception;
   
   type List is array (Positive range <>) of Unbounded_String;
   
   function Index (Haystack : List; Needle : String) return Positive is
   begin
      for Index in Haystack'Range loop
         if Haystack (Index) = Needle then
            return Index;
         end if;
      end loop;
      raise Not_In;
   end Index;

      
   function "+" (X, Y : String) return List is
   begin
      return (1 => To_Unbounded_String (X), 2 => To_Unbounded_String (Y));
   end "+";
   
   function "+" (X : List; Y : String) return List is
   begin
      return X & (1 => To_Unbounded_String (Y));
   end "+";
   
   Haystack : List := "Zig"+"Zag"+"Wally"+"Ronald"+"Bush"+"Krusty"+"Charlie"+"Bush"+"Bozo";

   procedure Check (Needle : String) is
   begin
      Put (Needle);
      Put_Line ("at" & Positive'Image (Index (Haystack, Needle)));
   exception
      when Not_In => Put_Line (" is not in");
   end Check;
begin
   Check ("Washington");
   Check ("Bush");
end Test_List_Index;
Task: Search a list

C: #include <stdio.h>
#include <string.h>

const char *haystack[] = {
  "Zig", "Zag", "Wally", "Ronald", "Bush", "Krusty", "Charlie",
  "Bush", "Boz", "Zag", NULL
};

int search_needle(const char *needle, const char **hs)
{
  int i = 0;
  while( hs[i] != NULL ) {
    if ( strcmp(hs[i], needle) == 0 ) return i;
    i++;
  }
  return -1;
}

int search_last_needle(const char *needle, const char **hs)
{
  int i, last=0;
  i = last = search_needle(needle, hs);
  if ( last < 0 ) return -1;
  while( hs[++i] != NULL ) {
    if ( strcmp(needle, hs[i]) == 0 ) {
      last = i;
    }
  }
  return last;
}

int main()
{
  printf("Bush is at %d\n", search_needle("Bush", haystack));
  if ( search_needle("Washington", haystack) == -1 )
    printf("Washington is not in the haystack\n");
  printf("First index for Zag: %d\n", search_needle("Zag", haystack));
  printf("Last index for Zag: %d\n", search_last_needle("Zag", haystack));
  return 0;
}
Task: Search a list



C#: using System;
using System.Collections.Generic;

class Program {
    static void Main(string[] args) {
        List<string> haystack = new List<string>() { "Zig", "Zag", "Wally", "Ronald", "Bush", "Krusty", "Charlie", "Bush", "Bozo" };

        foreach (string needle in new string[] { "Washington", "Bush" }) {
            int index = haystack.IndexOf(needle);
            
            if (index < 0) Console.WriteLine("{0} is not in haystack",needle);                
            else Console.WriteLine("{0} {1}",index,needle);
        }
    }
}
Task: Search a list


C++: #include <string>
#include <algorithm>
#include <iterator>
#include <cstddef>
#include <exception>
#include <iostream>


class not_found: public std::exception
{
public:
  not_found(std::string const& s): text(s + " not found") {}
  char const* what() const throw() { return text.c_str(); }
  ~not_found() throw() {}
private:
  std::string text;
};


std::size_t get_index(std::string* haystack, int haystack_size, std::string needle)
{
  std::size_t index = std::find(haystack, haystack+haystack_size, needle) - haystack;
  if (index == haystack_size)
    throw not_found(needle);
  else
    return index;
}



template<typename FwdIter>
 typename std::iterator_traits<FwdIter>::difference_type fwd_get_index(FwdIter first, FwdIter last, std::string needle)
{
  FwdIter elem = std::find(first, last, needle);
  if (elem == last)
    throw not_found(needle);
  else
    return std::distance(first, elem);
}


template<typename InIter>
 typename std::iterator_traits<InIter>::difference_type generic_get_index(InIter first, InIter last, std::string needle)
{
  typename std::iterator_traits<InIter>::difference_type index = 0;
  while (first != last && *first != needle)
  {
    ++index;
    ++first;
  }
  if (first == last)
    throw not_found(needle);
  else
    return index;
}




std::string haystack[] = { "Zig", "Zag", "Wally", "Ronald", "Bush", "Krusty", "Charlie", "Bush", "Bozo" };


template<typename T, std::size_t sz> T* begin(T (&array)[sz]) { return array; }
template<typename T, std::size_t sz> T* end(T (&array)[sz]) { return array + sz; }
template<typename T, std::size_t sz> std::size_t size(T (&array)[sz]) { return sz; }


void test(std::string const& needle)
{
  std::cout << "-- C style interface --\n";
  try
  {
    std::size_t index = get_index(haystack, size(haystack), needle);
    std::cout << needle << " found at index " << index << "\n";
  }
  catch(std::exception& exc) 
  {
    std::cout << exc.what() << "\n";
  }

  std::cout << "-- generic interface, first version --\n";
  try
  {
    std::size_t index = fwd_get_index(begin(haystack), end(haystack), needle);
    std::cout << needle << " found at index " << index << "\n";
  }
  catch(std::exception& exc) 
  {
    std::cout << exc.what() << "\n";
  }

  std::cout << "-- generic interface, second version --\n";
  try
  {
    std::size_t index = generic_get_index(begin(haystack), end(haystack), needle);
    std::cout << needle << " found at index " << index << "\n";
  }
  catch(std::exception& exc) 
  {
    std::cout << exc.what() << "\n";
  }
}

int main()
{
  std::cout << "\n=== Word which only occurs once ===\n";
  test("Wally");
  std::cout << "\n=== Word occuring multiple times ===\n";
  test("Bush");
  std::cout << "\n=== Word not occuring at all ===\n";
  test("Goofy");
}
Task: Search a list





Java: import java.util.List;
import java.util.Arrays;

List<String> haystack = Arrays.asList("Zig","Zag","Wally","Ronald","Bush","Krusty","Charlie","Bush","Bozo");

for (String needle : new String[]{"Washington","Bush"}) {
    int index = haystack.indexOf(needle);
    if (index < 0)
        System.out.println(needle + " is not in haystack");
    else
        System.out.println(index + " " + needle);
}
Task: Search a list







Python: haystack=["Zig","Zag","Wally","Ronald","Bush","Krusty","Charlie","Bush","Bozo"]

for needle in ("Washington","Bush"):
  try:
    print haystack.index(needle), needle
  except ValueError, value_error:
    print needle,"is not in haystack"
Task: Search a list








VB: Function IsInArray(stringToBeFound As Variant, arr As Variant, _
    Optional start As Integer = 1, Optional reverse As Boolean = False) As Long

    Dim i As Long, lo As Long, hi As Long, stp As Long
    
    IsInArray = -1
    If reverse Then
        lo = UBound(arr): hi = start: stp = -1
    Else
        lo = start: hi = UBound(arr): stp = 1
    End If
    For i = lo To hi Step stp 
        If StrComp(stringToBeFound, arr(i), vbTextCompare) = 0 Then
            IsInArray = i
            Exit For
        End If
    Next i
End Function
Public Sub search_a_list()
    Dim haystack() As Variant, needles() As Variant
    haystack = [{"Zig","Zag","Wally","Ronald","Bush","Krusty","Charlie","Bush","Bozo"}]
    needles = [{"Washington","Bush"}]
    For i = 1 To 2
        If IsInArray(needles(i), haystack) = -1 Then
            Debug.Print needles(i); " not found in haystack."
        Else
            Debug.Print needles(i); " is at position "; CStr(IsInArray(needles(i), haystack)); ".";
            Debug.Print " And last position is ";
            Debug.Print CStr(IsInArray(needles(i), haystack, 1, True)); "."
        End If
    Next i
End Sub
Task: Search a list




Go: package main

var haystack = []string{"Zig", "Zag", "Wally", "Ronald", "Bush", "Krusty",
    "Charlie", "Bush", "Bozo", "Zag", "mouse", "hat", "cup", "deodorant",
    "television", "soap", "methamphetamine", "severed cat heads", "foo",
    "bar", "baz", "quux", "quuux", "quuuux", "bazola", "ztesch", "foo",
    "bar", "thud", "grunt", "foo", "bar", "bletch", "foo", "bar", "fum",
    "fred", "jim", "sheila", "barney", "flarp", "zxc", "spqr", ";wombat",
    "shme", "foo", "bar", "baz", "bongo", "spam", "eggs", "snork", "foo",
    "bar", "zot", "blarg", "wibble", "toto", "titi", "tata", "tutu", "pippo",
    "pluto", "paperino", "aap", "noot", "mies", "oogle", "foogle", "boogle",
    "zork", "gork", "bork", "sodium", "phosphorous", "californium",
    "copernicium", "gold", "thallium", "carbon", "silver", "gold", "copper",
    "helium", "sulfur"}
Task: Search a list



C#: using System;
using System.Collections.Generic;

class Program {
    static void Main(string[] args) {
        List<string> haystack = new List<string>() { "Zig", "Zag", "Wally", "Ronald", "Bush", "Krusty", "Charlie", "Bush", "Bozo" };

        foreach (string needle in new string[] { "Washington", "Bush" }) {
            int index = haystack.IndexOf(needle);
            
            if (index < 0) Console.WriteLine("{0} is not in haystack",needle);                
            else Console.WriteLine("{0} {1}",index,needle);
        }
    }
}








Fortran: program main

 implicit none

 character(len=7),dimension(10) :: haystack = [  &
  'Zig    ',&
  'Zag    ',&
  'Wally  ',&
  'Ronald ',&
  'Bush   ',&
  'Krusty ',&
  'Charlie',&
  'Bush   ',&
  'Boz    ',&
  'Zag    ']

 call find_needle('Charlie')
 call find_needle('Bush')

 contains

	subroutine find_needle(needle)
	implicit none
	character(len=*),intent(in) :: needle
	integer :: i
	do i=1,size(haystack)
		if (needle==haystack(i)) then
			write(*,'(A,I4)') trim(needle)//' found at index:',i
			return
		end if
	end do
	write(*,'(A)') 'Error: '//trim(needle)//' not found.'
	end subroutine find_needle

 end program main
Task: Search a list

C: #include <stdio.h>
#include <string.h>

const char *haystack[] = {
  "Zig", "Zag", "Wally", "Ronald", "Bush", "Krusty", "Charlie",
  "Bush", "Boz", "Zag", NULL
};

int search_needle(const char *needle, const char **hs)
{
  int i = 0;
  while( hs[i] != NULL ) {
    if ( strcmp(hs[i], needle) == 0 ) return i;
    i++;
  }
  return -1;
}

int search_last_needle(const char *needle, const char **hs)
{
  int i, last=0;
  i = last = search_needle(needle, hs);
  if ( last < 0 ) return -1;
  while( hs[++i] != NULL ) {
    if ( strcmp(needle, hs[i]) == 0 ) {
      last = i;
    }
  }
  return last;
}

int main()
{
  printf("Bush is at %d\n", search_needle("Bush", haystack));
  if ( search_needle("Washington", haystack) == -1 )
    printf("Washington is not in the haystack\n");
  printf("First index for Zag: %d\n", search_needle("Zag", haystack));
  printf("Last index for Zag: %d\n", search_last_needle("Zag", haystack));
  return 0;
}










Fortran: program main

 implicit none

 character(len=7),dimension(10) :: haystack = [  &
  'Zig    ',&
  'Zag    ',&
  'Wally  ',&
  'Ronald ',&
  'Bush   ',&
  'Krusty ',&
  'Charlie',&
  'Bush   ',&
  'Boz    ',&
  'Zag    ']

 call find_needle('Charlie')
 call find_needle('Bush')

 contains

	subroutine find_needle(needle)
	implicit none
	character(len=*),intent(in) :: needle
	integer :: i
	do i=1,size(haystack)
		if (needle==haystack(i)) then
			write(*,'(A,I4)') trim(needle)//' found at index:',i
			return
		end if
	end do
	write(*,'(A)') 'Error: '//trim(needle)//' not found.'
	end subroutine find_needle

 end program main
Task: Search a list




Go: package main

var haystack = []string{"Zig", "Zag", "Wally", "Ronald", "Bush", "Krusty",
    "Charlie", "Bush", "Bozo", "Zag", "mouse", "hat", "cup", "deodorant",
    "television", "soap", "methamphetamine", "severed cat heads", "foo",
    "bar", "baz", "quux", "quuux", "quuuux", "bazola", "ztesch", "foo",
    "bar", "thud", "grunt", "foo", "bar", "bletch", "foo", "bar", "fum",
    "fred", "jim", "sheila", "barney", "flarp", "zxc", "spqr", ";wombat",
    "shme", "foo", "bar", "baz", "bongo", "spam", "eggs", "snork", "foo",
    "bar", "zot", "blarg", "wibble", "toto", "titi", "tata", "tutu", "pippo",
    "pluto", "paperino", "aap", "noot", "mies", "oogle", "foogle", "boogle",
    "zork", "gork", "bork", "sodium", "phosphorous", "californium",
    "copernicium", "gold", "thallium", "carbon", "silver", "gold", "copper",
    "helium", "sulfur"}







Fortran: program main

 implicit none

 character(len=7),dimension(10) :: haystack = [  &
  'Zig    ',&
  'Zag    ',&
  'Wally  ',&
  'Ronald ',&
  'Bush   ',&
  'Krusty ',&
  'Charlie',&
  'Bush   ',&
  'Boz    ',&
  'Zag    ']

 call find_needle('Charlie')
 call find_needle('Bush')

 contains

	subroutine find_needle(needle)
	implicit none
	character(len=*),intent(in) :: needle
	integer :: i
	do i=1,size(haystack)
		if (needle==haystack(i)) then
			write(*,'(A,I4)') trim(needle)//' found at index:',i
			return
		end if
	end do
	write(*,'(A)') 'Error: '//trim(needle)//' not found.'
	end subroutine find_needle

 end program main
Task: Search a list





Java: import java.util.List;
import java.util.Arrays;

List<String> haystack = Arrays.asList("Zig","Zag","Wally","Ronald","Bush","Krusty","Charlie","Bush","Bozo");

for (String needle : new String[]{"Washington","Bush"}) {
    int index = haystack.indexOf(needle);
    if (index < 0)
        System.out.println(needle + " is not in haystack");
    else
        System.out.println(index + " " + needle);
}






Fortran: program main

 implicit none

 character(len=7),dimension(10) :: haystack = [  &
  'Zig    ',&
  'Zag    ',&
  'Wally  ',&
  'Ronald ',&
  'Bush   ',&
  'Krusty ',&
  'Charlie',&
  'Bush   ',&
  'Boz    ',&
  'Zag    ']

 call find_needle('Charlie')
 call find_needle('Bush')

 contains

	subroutine find_needle(needle)
	implicit none
	character(len=*),intent(in) :: needle
	integer :: i
	do i=1,size(haystack)
		if (needle==haystack(i)) then
			write(*,'(A,I4)') trim(needle)//' found at index:',i
			return
		end if
	end do
	write(*,'(A)') 'Error: '//trim(needle)//' not found.'
	end subroutine find_needle

 end program main
Task: Search a list







Python: haystack=["Zig","Zag","Wally","Ronald","Bush","Krusty","Charlie","Bush","Bozo"]

for needle in ("Washington","Bush"):
  try:
    print haystack.index(needle), needle
  except ValueError, value_error:
    print needle,"is not in haystack"




Fortran: program main

 implicit none

 character(len=7),dimension(10) :: haystack = [  &
  'Zig    ',&
  'Zag    ',&
  'Wally  ',&
  'Ronald ',&
  'Bush   ',&
  'Krusty ',&
  'Charlie',&
  'Bush   ',&
  'Boz    ',&
  'Zag    ']

 call find_needle('Charlie')
 call find_needle('Bush')

 contains

	subroutine find_needle(needle)
	implicit none
	character(len=*),intent(in) :: needle
	integer :: i
	do i=1,size(haystack)
		if (needle==haystack(i)) then
			write(*,'(A,I4)') trim(needle)//' found at index:',i
			return
		end if
	end do
	write(*,'(A)') 'Error: '//trim(needle)//' not found.'
	end subroutine find_needle

 end program main