-2
2 arraya即item
和tra
比较阵列元件
item
包含
B
C
M
G
D
E
tra
数组包含
BM
BDGE
MDGC
BMDG
BMDC
我需要找到每个元素的计数在item
阵列存在于tra
阵列
例如B
计数是4 C
计数是2
对于此任务我利用了count()
和计数器变量。
这里是我的代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace apriori
{
class apriori
{
static void Main(string[] args)
{
int t, n, s, i, j, k, q;
int counter = 0;
int[] count = new int[6];
Console.WriteLine("enter the number of transactions t");
t = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("enter the number of items n");
n = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("enter minimum support s");
s = Convert.ToInt32(Console.ReadLine());
String[] tra = new String[t];
String[] item = new String[n];
Console.WriteLine("enter transactions representing one alphabet each item");
for (i = 0; i < t; i++)
{
tra[i] = Console.ReadLine();
}
Console.WriteLine("list of transactions");
foreach (String it in tra)
{
Console.WriteLine(it);
}
Console.WriteLine("enter items");
for (j = 0; j < n; j++)
{
item[j] = Console.ReadLine();
}
Console.WriteLine("list of items");
foreach (String ite in item)
{
Console.WriteLine(ite);
}
for (i = 0; i < n; i++)
{
for (j = 0; j < t; j++)
{
if (item[i]==tra[j])
{
count[i]=counter++;
}
}
counter=0;
}
你的问题是什么?你的代码有问题吗?如果是,什么?顺便说一句,看看[格式帮助](http://stackoverflow.com/editing-help)和[如何问](http://stackoverflow.com/questions/how-to-ask)了解如何在StackOverflow上编写问题。 – Albireo
您的代码有问题吗?或者您在寻找更好的方法来实现您的任务(例如,使用LINQ)? –
看起来像一个家庭作业。 –