问题
I had written the code for finding duplicate elements in C but now I am stuck at implementing the same code in freemarker Can anyone help?
int n, a[10], b[10], count = 0, c, d;
printf("Enter number of elements in array\n");
scanf("%d",&n);
printf("Enter %d integers\n", n);
for(c=0;c<n;c++)
scanf("%d",&a[c]);
for(c=0;c<n;c++)
{
for(d=0;d<count;d++)
{
if(a[c]==b[d])
break;
}
if(d==count)
{
b[count] = a[c];
count++;
}
}
printf("Array obtained after removing duplicate elements\n");
for(c=0;c<count;c++)
printf("%d\n",b[c]);
回答1:
You can use freemarker sequences. Probably not super efficient but I've used this to group close to max size lines on invoices and such.
<#assign seen_style = []>
<#list record.item?sort_by("custcol_stylesort") as lineitem>
<#assign groupId = lineitem.item>
<#if seen_style?seq_contains(groupId)> <!-- no if body is intentional; skips seen style -->
<#else>
<#assign seen_style = seen_style + [groupId]>
<p>Do something with ${groupId}</p>
</#if>
</#list>
来源:https://stackoverflow.com/questions/51738960/how-to-remove-duplicate-elements-in-a-array-using-freemarker