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 transponder
- {
- class transponder
- {
- struct ST {
- public DateTime Time;
- public int x;
- public int y;
- }
- static List<ST> ls = new List<ST>();
- static ST ls1;
- static int n = 2;
- static void exn(){
- if (n > 2) { Console.WriteLine(); }
- if (n == 3) n++;
- Console.WriteLine($"Exercise {n++}.");
- }
- static void ex1() {
- StreamReader sr = new StreamReader("signal.txt");
- while (!sr.EndOfStream) {
- var line = sr.ReadLine().Split();
- ls1.Time = new DateTime(1,1,1,Convert.ToInt16(line[0]), //hour
- Convert.ToInt16(line[1]), //min
- Convert.ToInt16(line[2])); //sec
- ls1.x = Convert.ToInt16(line[3]);
- ls1.y = Convert.ToInt16(line[4]);
- ls.Add(ls1);
- }
- sr.Close();
- //foreach (var e in ls)
- //{
- // Console.WriteLine($"{e.Time.ToLongTimeString()} {e.x} {e.y}");
- //}
- }
- static void ex2() {
- exn();
- Console.Write("Give the ordinal number of the signal: ");
- int numb = Convert.ToInt16(Console.ReadLine());
- Console.WriteLine($"x={ls[numb - 1].x} y={ls[numb - 1].y}");
- }
- static int interval(DateTime time1, DateTime time2) {
- //int timediff = Convert.ToInt16(time2 - time1).TotalSeconds;
- //return timediff;
- return (int)(time2 - time1).TotalSeconds;
- }
- static void ex4() {
- exn();
- DateTime first = ls[0].Time;
- DateTime last = ls[ls.Count-1].Time;
- int h, m, s, totalsec;
- totalsec = interval(first, last);
- h = totalsec / 3600;
- totalsec -= h * 3600;
- m = totalsec / 60;
- totalsec -= m * 60;
- s = totalsec;
- Console.WriteLine($"Time difference: {h}:{m}:{s}");
- }
- static void ex5() {
- exn();
- //int minx, maxx, miny, maxy;
- //maxx=minx = ls[0].x;
- //maxy=miny = ls[0].y;
- //foreach (var e in ls){
- // if (e.x<minx) minx = e.x;
- // if (e.x>maxx) maxx = e.x;
- // if (e.y<miny) miny = e.y;
- // if (e.y>maxy) maxy = e.y;
- //}
- //Console.WriteLine($"Bottom left: {minx};{miny}, top right: {maxx};{maxy}");
- Console.WriteLine($"Bottom left: {ls.Min(c => c.x)},{ls.Min(c => c.y)} top right: {ls.Max(c => c.x)};{ls.Max(c => c.y)}");
- }
- static void ex6() {
- exn();
- double distance = 0;
- for (int i = 0; i < ls.Count-1; i++){
- double dx = (ls[i].x - ls[i+1].x);
- double dy = (ls[i].y - ls[i+1].y);
- distance += Math.Sqrt(dx*dx+dy*dy);
- }
- Console.WriteLine($"Total distance: {distance:F3} units");
- }
- static void ex7() {
- StreamWriter sw = new StreamWriter("missing.txt");
- int timediff, corddiffx, corddiffy, timecount, cordcount;
- for (int i = 0; i < ls.Count - 1; i++){
- timediff = interval(ls[i].Time, ls[i + 1].Time)/60;
- corddiffx = (ls[i].x - ls[i + 1].x);
- corddiffy = (ls[i].y - ls[i + 1].y);
- timecount = cordcount = 0;
- if (timediff > 5) {
- timecount += (timediff-1) / 5;
- }
- if (corddiffx>10){
- cordcount += (corddiffx-1) / 10;
- }
- if (corddiffy>10){
- cordcount += (corddiffy - 1) / 10;
- }
- if (timecount != 0 || cordcount != 0)
- {
- sw.Write(ls[i+1].Time.ToString("%H %m %s "));
- if (timecount>cordcount){
- sw.WriteLine($"time difference {timecount}");
- }
- else
- {
- sw.WriteLine($"coordinate difference {cordcount}");
- }
- sw.WriteLine();
- }
- }
- sw.Close();
- }
- static void Main(string[] args)
- {
- ex1();
- ex2();
- //ex3();
- ex4();
- ex5();
- ex6();
- ex7();
- Console.ReadKey();
- }
- }
- }
- /*
- 3 11 19 122 644
- 3 16 19 120 643
- 3 21 19 126 639
- 3 26 19 131 641
- 3 27 55 124 651
- 3 31 50 134 649
- 3 36 50 126 650
- 3 41 50 129 648
- 3 46 50 129 647
- 3 50 22 119 653
- 3 55 22 111 662
- 3 55 33 101 669
- 4 0 33 99 677
- 4 5 33 91 672
- 4 10 33 89 670
- 4 15 33 85 668
- 4 25 33 86 671
- 4 30 33 83 680
- 4 35 33 80 677
- 4 40 33 88 686
- 4 45 33 87 690
- 4 50 33 81 698
- 4 55 33 74 678
- 5 5 33 78 684
- 5 10 33 73 690
- 5 12 42 70 680
- 5 17 42 75 687
- 5 22 42 75 695
- 5 27 42 68 701
- 5 32 42 65 694
- 5 37 42 72 698
- 5 42 42 76 692
- 5 47 42 71 699
- 5 52 42 71 701
- 5 57 42 77 704
- 6 2 42 73 709
- 6 7 42 76 713
- 6 22 42 94 724
- 6 32 42 82 698
- 6 37 42 74 691
- 6 42 42 81 695
- 6 47 42 85 692
- 6 52 42 88 684
- 6 57 42 95 679
- 7 2 42 96 682
- 7 7 42 99 678
- 7 12 42 104 676
- 7 17 42 104 682
- 7 22 42 103 676
- 7 27 42 94 670
- 7 31 44 88 660
- 7 36 44 87 653
- 7 41 44 85 660
- 7 46 44 93 656
- 7 51 44 100 656
- 7 56 44 96 660
- 8 1 44 95 662
- 8 6 44 94 664
- 8 11 44 87 673
- 8 16 44 94 665
- 8 21 44 95 663
- 8 26 44 104 663
- 8 31 44 104 658
- 8 36 44 104 655
- 8 37 26 112 665
- 8 42 26 112 674
- 8 43 29 102 683
- 8 48 29 110 687
- 8 53 29 114 692
- 8 58 29 112 692
- 9 3 29 112 691
- 9 8 29 110 693
- 9 10 1 120 693
- 9 15 1 111 691
- 9 20 1 109 685
- 9 24 10 99 682
- 9 29 10 100 682
- 9 30 27 110 690
- 9 35 27 117 684
- 9 40 27 119 675
- 9 45 27 118 682
- 9 50 27 121 684
- 9 55 27 126 690
- 10 0 27 123 689
- 10 5 27 119 694
- 10 10 27 127 685
- 10 15 27 121 694
- 10 20 27 125 700
- 10 25 27 129 703
- 10 30 27 125 702
- 10 35 27 123 707
- 10 38 59 113 705
- 10 43 59 109 700
- 10 44 45 111 690
- 10 46 26 121 690
- 10 47 50 111 696
- 10 48 17 121 687
- 10 51 38 131 696
- 10 56 38 135 698
- 11 1 38 140 693
- 11 6 38 141 694
- 11 11 38 143 696
- 11 16 38 136 688
- 11 21 38 132 687
- 11 26 38 128 679
- 11 31 38 122 683
- 11 34 19 132 674
- 11 39 19 139 665
- 11 40 48 147 675
- 11 43 45 137 673
- 11 48 45 133 678
- 11 49 59 143 679
- 11 54 59 136 683
- 11 56 52 126 682
- 12 1 52 134 676
- 12 2 46 124 674
- 12 7 46 123 681
- 12 12 46 116 681
- 12 17 46 109 672
- 12 22 46 114 675
- 12 26 29 113 665
- 12 31 29 116 663
- 12 36 29 112 662
- 12 41 29 106 664
- 12 41 32 113 674
- 12 41 48 123 683
- 12 46 48 114 687
- 12 51 39 104 677
- 12 56 39 103 686
- 13 1 39 109 690
- 13 5 53 119 699
- 13 9 40 109 706
- 13 14 40 112 708
- 13 19 40 110 699
- 13 24 40 113 692
- 13 29 40 114 700
- 13 34 40 108 691
- 13 39 40 99 682
- 13 44 40 95 680
- 13 48 25 89 690
- 13 53 25 84 687
- 13 58 25 79 685
- 14 3 25 83 678
- 14 8 25 83 672
- 14 11 49 83 662
- 14 16 49 92 663
- 14 21 49 100 660
- 14 26 49 97 661
- 14 31 49 100 658
- 14 36 49 104 666
- 14 41 49 110 664
- 14 46 49 102 663
- 14 51 49 102 659
- 14 51 50 108 669
- 14 56 50 107 672
- 14 58 31 103 682
- 15 3 31 95 682
- 15 8 31 99 678
- 15 13 31 98 680
- 15 18 31 101 673
- 15 23 31 96 666
- 15 26 18 92 676
- 15 31 18 100 679
- 15 31 51 98 689
- 15 36 1 95 679
- 15 41 1 87 676
- 15 46 1 88 675
- 15 51 1 89 671
- 15 56 1 86 677
- 16 1 1 88 682
- 16 5 16 83 672
- 16 10 16 82 664
- 16 15 16 81 666
- 16 20 16 74 661
- 16 25 16 67 661
- 16 27 36 69 651
- 16 32 36 74 642
- 16 37 36 70 649
- 16 42 36 76 656
- 16 47 36 73 659
- 16 52 36 82 662
- 16 57 36 78 662
- 17 2 36 72 662
- 17 6 34 69 672
- 17 11 34 78 675
- 17 15 7 75 685
- 17 16 19 85 683
- 17 21 19 85 688
- 17 24 20 76 678
- 17 29 20 71 671
- 17 30 3 72 661
- 17 31 4 82 670
- 17 36 4 89 664
- 17 41 4 83 666
- 17 46 4 77 670
- 17 51 4 85 671
- 17 56 4 77 673
- 18 1 4 70 670
- 18 5 52 73 680
- 18 10 52 69 688
- 18 15 52 70 680
- 18 20 52 68 682
- 18 25 52 65 685
- 18 30 52 58 692
- 18 35 52 62 689
- 18 40 52 57 694
- 18 44 20 52 684
- 18 49 20 46 682
- 18 54 20 45 681
- 18 59 20 49 672
- 19 4 20 44 678
- 19 9 20 42 669
- 19 14 20 35 662
- 19 19 20 30 665
- 19 22 45 20 671
- 19 27 45 14 670
- 19 32 45 6 673
- 19 37 45 6 669
- 19 42 45 5 676
- 19 47 45 12 681
- 19 52 45 20 689
- 19 57 45 26 685
- 20 0 34 27 695
- 20 4 31 17 700
- 20 9 31 13 699
- 20 14 31 17 699
- 20 19 31 20 705
- 20 24 31 26 712
- 20 29 31 25 708
- 20 33 24 20 718
- 20 38 24 29 725
- 20 43 24 29 723
- 20 48 24 20 726
- 20 53 24 23 717
- 20 55 40 17 727
- 21 0 40 21 721
- 21 5 40 13 727
- 21 10 40 4 722
- 21 15 40 11 721
- 21 20 40 12 718
- 21 25 40 19 711
- 21 30 40 13 720
- 21 33 27 21 710
- 21 38 27 27 719
- 21 43 27 29 714
- 21 48 27 31 708
- 21 50 21 40 698
- 21 53 59 50 706
- 21 58 59 44 713
- 22 3 59 36 713
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement