请问这个“找出不是两个数组共有的元素”C#有什么问题?(已解决)

题目
在运行题上的实例时无法输出最后一个“1”
这是查错结果

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            string op1 = Console.ReadLine();
            string op2 = Console.ReadLine();
            string op3 = op1.Substring(0, op1.IndexOf(" "));
            string op4 = op1.Substring(0, op2.IndexOf(" "));
            string op5 = op1.Substring(op1.IndexOf(" ")+1);
            string op6 = op2.Substring(op1.IndexOf(" ")+1);
            int n1, n2,flag;
            n1 = int.Parse(op3);
            n2 = int.Parse(op4);
            string[] a = op5.Split(' ');
            string[] b = op6.Split(' ');
            string[] c = new string[20];
            int count = 0;
            for (int j = 0; j < n1; j++)
            {
                flag = 0;
                for ( int i = 0; i < n2; i++)
                {
                    if (a[j] == b[i])
                        flag = 1;
                }
                if (flag == 0)
                {
                    int h, flag1 = 0;
                    for (h = 0; h <=count; h++)
                    {
                        if (c[h] == a[j])
                        {
                            flag1 = 1;
                        }
                    }
                    if (flag1 == 0)
                    {
                        c[count] = a[j];
                        count++;
                    }
                }
            }
            for (int j = 0; j < n2; j++)
            {
                flag = 0;
                for (int i = 0; i < n1; i++)
                {
                    if (b[j] == a[i])
                        flag = 1;
                }
                if (flag == 0)
                {
                    int h, flag1 = 0;
                    for (h = 0; h <= count; h++)
                    {
                        if (c[h] == b[j])
                        {
                            flag1 = 1;
                        }
                    }
                    if (flag1 == 0)
                    {
                        c[count] = b[j];
                        count++;
                    }
                }
            }
            Console.Write(c[0]);
            for (int i = 1; i < count; i++)
            {
                Console.Write(" " + c[i]);
            }
        }
    }
}

求大佬们指导。
已解决,改动代码如下。

using System;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            string str1 = Console.ReadLine();
            string str2 = Console.ReadLine();
            int a = str1.IndexOf(" ");
            int b = str2.IndexOf(" ");
            int c = Convert.ToInt32(str1.Substring(0, a));
            int d = Convert.ToInt32(str2.Substring(0, b));
            string str3 = str1.Substring(a + 1);
            string str4 = str2.Substring(b + 1);
            string[] str5 = str3.Split(' ');
            string[] str6 = str4.Split(' ');
            int[] x = new int[c];
            int[] y = new int[d];
            string t = "";
            for (int i = 0; i < c; i++)
            {
                x[i] = Convert.ToInt32(str5[i]);
            }
            for (int o = 0; o < d; o++)
            {
                y[o] = Convert.ToInt32(str6[o]);
            }
            int z;
            for (int m = 0; m < c; m++)
            {
                bool flag1 = true;
                z = x[m];
                foreach (int val in y)
                {
                    if (val == z)
                    {
                        flag1 = false;
                        break;
                    }
                    else
                        continue;
                }
                if (flag1 == true)
                    t += z.ToString() + " ";
                else
                    continue;
            }
            int h;
            for (int n = 0; n < d; n++)
            {
                bool flag2 = true;
                h = y[n];
                foreach (int val in x)
                {
                    if (val == h)
                    {
                        flag2 = false;
                        break;
                    }
                    else
                        continue;
                }
                if (flag2 == true)
                    t += h.ToString() + " ";
                else
                    continue;
            }
            int e = t.Length;
            string q = t.Substring(0, e - 1);
            string[] qw = q.Split(' ');
            int[] r = new int[qw.Length];
            for (int u = 0; u < qw.Length; u++)
            {
                r[u] = Convert.ToInt32(qw[u]);
            }
            for (int sa = 0; sa < qw.Length; sa++)
            {
                for (int sb = sa+1; sb < qw.Length;sb++)
                {
                    if (r[sa] == r[sb])
                        r[sb] = 10086;

                }
            }
            string w = "";
            for (int sc = 0; sc < qw.Length; sc++)
            {
                if (r[sc] != 10086)
                {
                    w += (r[sc]).ToString() + " ";
                }
            }
            int ew = w.Length;
            string qwe = w.Substring(0, ew - 1);
            Console.WriteLine(qwe);


        }
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值