Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.IO;
- namespace func
- {
- class Program
- {
- static void Main(string[] args)
- {
- const string fileInput = "../../input.txt";
- const string fileOutput = "../../output.txt";
- int[] inp = readFile(fileInput);
- int dapan = task(inp);
- writeFile(fileOutput, dapan.ToString());
- }
- public static int task(int[] a)
- {
- int total = 0;
- int[] temp = new int[findMax(a) + 1];
- foreach(int value in a)
- {
- temp[value]++;
- }
- foreach (int value in temp)
- {
- if (value >= 2) total += value;
- }
- return total;
- }
- public static int findMax(int[] a)
- {
- int max = a[0];
- for (int i = 1; i < a.Length; i++)
- {
- max = Math.Max(a[i], max);
- }
- return max;
- }
- public static int[] readFile(string path)
- {
- FileStream fs = new FileStream(path, FileMode.Open);
- StreamReader sReader = new StreamReader(fs, Encoding.UTF8);
- int n = int.Parse(sReader.ReadLine());
- int[] res = new int[n];
- string[] temp = sReader.ReadLine().Split(' ');
- for (int i = 0; i < n; i++)
- {
- res[i] = int.Parse(temp[i]);
- }
- sReader.Close();
- fs.Close();
- Console.WriteLine("Doc file thanh cong !");
- return res;
- }
- public static void writeFile(string path, string data)
- {
- FileStream fsW = new FileStream(path, FileMode.Create);
- StreamWriter sWriter = new StreamWriter(fsW, Encoding.Unicode);
- sWriter.Write(data);
- sWriter.Flush();
- fsW.Close();
- fsW.Close();
- Console.WriteLine("Ghi file thanh cong !");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement