-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode
More file actions
139 lines (118 loc) · 3.06 KB
/
code
File metadata and controls
139 lines (118 loc) · 3.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/*
N 개의 값으로 이루어진 배열이 주어졌을 때, 주어진 K 횟수 만큼 오른쪽으로 배열을 회전(rotating) 시킵니다.
모든 원소는 오른쪽으로 K 만큼 이동하게 되며, 배열 오른쪽 밖으로 밀려난 원소는 왼쪽으로부터 추가됩니다.
예를 들면 K=1 일때, 가장 오른쪽에서 있던 원소는 왼쪽 첫번째 위치로 이동하게 됩니다.
예를 들면, 배열 [3, 8, 9, 7, 6] 을 한번 회전시키면 [6, 3, 8, 9, 7] 이 되고, K = 3 번 회전 시키면 [9, 7, 6, 3, 8] 이 됩니다.
입력은 두 행의 표준 입력입니다.
첫 번째 행은 space 로 구분된 문자열입니다.
두 번째 행은 회전시킬 횟수 K 값입니다. 값 K는 반드시 정수로만 주어집니다.
예를들면 다음과 같은 입력이 주어졌을 때
3 8 9 7 6
3
다음과 같이 출력해주시면 됩니다.
9 7 6 3 8
*/
/*
삼각형 형태를 구하라.
*/
using System;
namespace _000_test_01
{
class Program
{
static void Main(string[] args)
{
string arr;
try
{
arr = Console.ReadLine();
}
catch(Exception e) { Console.WriteLine(e.Message); return; }
string[] src_arr = arr.Split(new char[] { ' ' });
int k;
try
{
string _k = Console.ReadLine();
k = Convert.ToInt32(_k);
}
catch(Exception e) { Console.WriteLine(e.Message); return; }
int len;
try
{
len = src_arr.Length;
}
catch(Exception e) { Console.WriteLine(e.Message); return; }
while(k < 0)
k += len;
while(k >= len)
k -= len;
string[] dst_arr = new string[len];
for(int idx_src = 0, idx_dst = k; idx_src < len; idx_src++, idx_dst++)
{
if(idx_dst >= len)
idx_dst = 0;
dst_arr[idx_dst] = src_arr[idx_src];
}
try
{
foreach(var a in dst_arr)
Console.Write(a + " ");
Console.WriteLine();
}
catch(Exception e) { Console.WriteLine(e.Message); return; }
//string arr;
//try
//{
// arr = Console.ReadLine();
//}
//catch(Exception e) { Console.WriteLine(e.Message); return; }
//string[] arr_src = arr.Split(new char[] { ' ' });
//int retval = 0;
//if(arr_src.Length != 3)
//{
// try
// {
// Console.WriteLine(retval);
// }
// catch(Exception e) { Console.WriteLine(e.Message); }
// return;
//}
//int[] arr_n = new int[3];
//int idx_max = 0;
//int sum_other = 0;
//for(int i = 0; i < 3; i++)
//{
// try
// {
// arr_n[i] = Convert.ToInt32(arr_src[i]);
// if(arr_n[i] > arr_n[idx_max])
// {
// sum_other += arr_n[idx_max];
// idx_max = i;
// }
// else if(i != 0)
// sum_other += arr_n[i];
// if(arr_n[i] <= 0
// || (i == 2 && sum_other <= arr_n[idx_max]))
// {
// retval = -1;
// break;
// }
// if(i >= 1 && arr_n[i - 1] == arr_n[i])
// retval++;
// if(retval == 0 && i == 2 && arr_n[0] == arr_n[2])
// retval++;
// }
// catch(Exception e)
// {
// if((e as FormatException) != null)
// {
// retval = -1;
// }
// break;
// }
//}
//Console.WriteLine(++retval);
}
}
}