C# TRANSLATION FOR THE JAVA CODE ON SITE:
private static int FreshPromotion(string[][] codeList, string[] shoppingCart)
{
// Start at 0 index for both the code list and shopping cart.
int cartIdx = 0, codeIdx = 0;
while (cartIdx < [Link] && codeIdx < [Link])
{
string cur = shoppingCart[cartIdx];
// If the first fruit of the codeList is anything or if it matches the
current fruit at the cart idx.
if ((codeList[codeIdx][0].Equals("anything") || codeList[codeIdx]
[0].Equals(cur)) && HasOrder(shoppingCart, cartIdx, codeList[codeIdx]))
{
cartIdx += codeList[codeIdx++].Length;
}
else
{
cartIdx++;
}
}
// If the all the codeList is present then return 1, else 0.
return codeIdx == [Link] ? 1 : 0;
}
private static bool HasOrder(string[] shoppingCart, int idx, string[] order)
{
// Loop through the codeList to check if the fruits are in order.
foreach (string s in order)
{
if (idx < [Link] && ([Link]("anything") ||
shoppingCart[idx].Equals(s)))
{
idx++;
}
else
{
return false;
}
}
return true;
}
using System;
using [Link];
public class Foo
{
/*
* Complete the 'IsBuyerWinner' function below.
*
* The function is expected to return an Integer.
* The function accepts following parameters:
* 1. List (STRING_ARRAY) - codeList
* 2. List (STRING_ARRAY) - shoppingCart
*/
public static int IsBuyerWinner(List<string> codeList, List<string>
shoppingCart)
{
}
}
public class Solution
{
public static void Main(string[] args)
{
int codeListCount = Convert.ToInt32([Link]().Trim());
List<string> codeList = new List<string>();
for (int i = 0; i < codeListCount; i++)
{
string codeListItem = [Link]();
[Link](codeListItem);
}
int shoppingCartCount = Convert.ToInt32([Link]().Trim());
List<string> shoppingCart = new List<string>();
for (int i = 0; i < shoppingCartCount; i++)
{
string shoppingCartItem = [Link]();
[Link](shoppingCartItem);
}
int foo = [Link](codeList, shoppingCart);
[Link](foo);
}
}
POVEZANO PREKO GPT-A:
using System;
using [Link];
public class Foo
{
/*
* Complete the 'IsBuyerWinner' function below.
*
* The function is expected to return an Integer.
* The function accepts following parameters:
* 1. List (STRING_ARRAY) - codeList
* 2. List (STRING_ARRAY) - shoppingCart
*/
public static int IsBuyerWinner(List<string> codeList, List<string>
shoppingCart)
{
string[][] codeListArray = new string[[Link]][];
for (int i = 0; i < [Link]; i++)
{
codeListArray[i] = codeList[i].Split(' ');
}
string[] shoppingCartArray = [Link]();
// Start at 0 index for both the code list and shopping cart.
int cartIdx = 0, codeIdx = 0;
while (cartIdx < [Link] && codeIdx <
[Link])
{
string cur = shoppingCartArray[cartIdx];
// If the first fruit of the codeList is anything or if it matches the
current fruit at the cart idx.
if ((codeListArray[codeIdx][0].Equals("anything") ||
codeListArray[codeIdx][0].Equals(cur)) && HasOrder(shoppingCartArray, cartIdx,
codeListArray[codeIdx]))
{
cartIdx += codeListArray[codeIdx++].Length;
}
else
{
cartIdx++;
}
}
// If the all the codeList is present then return 1, else 0.
return codeIdx == [Link] ? 1 : 0;
}
private static bool HasOrder(string[] shoppingCart, int idx, string[] order)
{
// Loop through the codeList to check if the fruits are in order.
foreach (string s in order)
{
if (idx < [Link] && ([Link]("anything") ||
shoppingCart[idx].Equals(s)))
{
idx++;
}
else
{
return false;
}
}
return true;
}
}
public class Solution
{
public static void Main(string[] args)
{
int codeListCount = Convert.ToInt32([Link]().Trim());
List<string> codeList = new List<string>();
for (int i = 0; i < codeListCount; i++)
{
string codeListItem = [Link]();
[Link](codeListItem);
}
int shoppingCartCount = Convert.ToInt32([Link]().Trim());
List<string> shoppingCart = new List<string>();
for (int i = 0; i < shoppingCartCount; i++)
{
string shoppingCartItem = [Link]();
[Link](shoppingCartItem);
}
int result = [Link](codeList, shoppingCart);
[Link](result);
}
}
KOMENTARI NA BHS: