練習用です。いろんなものがごちゃまぜです。
Revision | 20efdaaf1521425cdad3967b5250f89d0c142913 (tree) |
---|---|
Time | 2017-04-01 21:33:35 |
Author | ![]() |
Commiter | 渡邉 喜光 |
Merge branch 'master' of git.pf.osdn.jp:/gitroot/b/be/bellyoshi/VSPRAC
@@ -0,0 +1,23 @@ | ||
1 | +#include <iostream> | |
2 | + | |
3 | +using namespace std; | |
4 | + | |
5 | +int gcd(int a, int b){ | |
6 | + int mod = !0; | |
7 | + while(mod != 0 ){ | |
8 | + mod = a % b; | |
9 | + if (mod > b){ | |
10 | + a = mod; | |
11 | + } else { | |
12 | + a = b; | |
13 | + b = mod; | |
14 | + } | |
15 | + } | |
16 | + return a; | |
17 | +} | |
18 | +int main(int argc, char const *argv[]) { | |
19 | + int x, y; | |
20 | + cin >> x >> y; | |
21 | + cout << gcd(x,y) << endl; | |
22 | + return 0; | |
23 | +} |
@@ -0,0 +1,57 @@ | ||
1 | +#include <iostream> | |
2 | + | |
3 | +using namespace std; | |
4 | +class sorter { | |
5 | + int count; | |
6 | + int *array; | |
7 | +public: | |
8 | + sorter(int count){ | |
9 | + this->count = count; | |
10 | + array = new int[count]; | |
11 | + } | |
12 | + ~sorter(){ | |
13 | + delete [] array; | |
14 | + } | |
15 | + void input(); | |
16 | + void output(); | |
17 | + void sort(); | |
18 | +}; | |
19 | + | |
20 | +void sorter::input(){ | |
21 | + for (int i = 0; i < count; i++) { | |
22 | + cin >> array[i]; | |
23 | + } | |
24 | +} | |
25 | + | |
26 | +void sorter::output(){ | |
27 | + for (int i = 0; i < count; i++) { | |
28 | + cout << array[i]; | |
29 | + if(i < count - 1){ | |
30 | + cout << " "; | |
31 | + }else{ | |
32 | + cout << endl; | |
33 | + } | |
34 | + } | |
35 | +} | |
36 | + | |
37 | +void sorter::sort(){ | |
38 | + for (int i = 1; i < count; i++) { | |
39 | + output(); | |
40 | + int key = array[i]; | |
41 | + int j = i - 1; | |
42 | + while (j >= 0 && array[j] > key) { | |
43 | + array[j + 1] = array[j]; | |
44 | + j--; | |
45 | + } | |
46 | + array[j + 1] = key; | |
47 | + } | |
48 | + output(); | |
49 | +} | |
50 | +int main(int argc, char const *argv[]) { | |
51 | + int count; | |
52 | + cin >> count; | |
53 | + sorter s = sorter(count); | |
54 | + s.input(); | |
55 | + s.sort(); | |
56 | + return 0; | |
57 | +} |
@@ -0,0 +1,139 @@ | ||
1 | +#include <iostream> | |
2 | +#include <cmath> | |
3 | +#include <cassert> | |
4 | + | |
5 | +using namespace std; | |
6 | + | |
7 | +typedef unsigned int MEMTYPE; | |
8 | + | |
9 | +class mybitset { | |
10 | + MEMTYPE *mem; | |
11 | + int size; | |
12 | + bool ismemfree; | |
13 | +public: | |
14 | + int bitlen(){ | |
15 | + return sizeof(MEMTYPE) * 8; | |
16 | + } | |
17 | + mybitset(){ | |
18 | + ismemfree = true; | |
19 | + } | |
20 | + void setsize(int size){ | |
21 | + this->size = size; | |
22 | + mem = new MEMTYPE[size / bitlen() + 1]; | |
23 | + ismemfree = false; | |
24 | + } | |
25 | + ~mybitset(){ | |
26 | + if (!ismemfree){ | |
27 | + delete [] mem; | |
28 | + } | |
29 | + } | |
30 | + bool get(int pos){ | |
31 | + MEMTYPE bit = 1 << (pos % bitlen()); | |
32 | + return (mem[pos / bitlen()] & bit) != 0; | |
33 | + }; | |
34 | + void set(int pos){ | |
35 | + MEMTYPE bit = 1 << (pos % bitlen()); | |
36 | + mem[pos / bitlen()] |= bit; | |
37 | + }; | |
38 | + void reset(int pos){ | |
39 | + MEMTYPE bit = ~(1 << (pos % bitlen())); | |
40 | + mem[pos / bitlen()] &= bit; | |
41 | + } | |
42 | +}; | |
43 | + | |
44 | +class primer { | |
45 | + mybitset isprime; | |
46 | + int max; | |
47 | +public: | |
48 | + bool getPrime(int number); | |
49 | + primer(int max); | |
50 | +}; | |
51 | + | |
52 | +bool primer::getPrime(int number){ | |
53 | + assert(max > number); | |
54 | + if (max > number){ | |
55 | + return isprime.get(number); | |
56 | + } | |
57 | + //assert(max * max > number); | |
58 | + //for(int i = 0; i < max ; i++){ | |
59 | + // if (isprime.get(i)){ | |
60 | + // if (number % i == 0){ | |
61 | + // return false; | |
62 | + // } | |
63 | + // } | |
64 | + //} | |
65 | + return true; | |
66 | +} | |
67 | +primer::primer(int max){ | |
68 | + this->max = max; | |
69 | + isprime.setsize(max + 1); | |
70 | + //エラトステネスの篩で素数かどうかの判定 | |
71 | + isprime.reset(0); | |
72 | + isprime.reset(1); | |
73 | + for(int i = 2; i < max; i++){ | |
74 | + isprime.set(i); | |
75 | + } | |
76 | + for(int i = 2; i < sqrt(max); i++){ | |
77 | + if(isprime.get(i)){ | |
78 | + for(int j = 2; i * j < max; j++){ | |
79 | + isprime.reset(i * j); | |
80 | + } | |
81 | + } | |
82 | + } | |
83 | +} | |
84 | + | |
85 | + | |
86 | +int main(int argc, char const *argv[]) { | |
87 | + int count; | |
88 | + cin >> count; | |
89 | + int prime_count = 0; | |
90 | + primer p = primer(100000000); | |
91 | + for (int i = 0; i < count; i++) { | |
92 | + int number; | |
93 | + cin >> number; | |
94 | + if (p.getPrime(number)){ | |
95 | + prime_count++; | |
96 | + } | |
97 | + } | |
98 | + cout << prime_count << endl; | |
99 | + return 0; | |
100 | +} | |
101 | + | |
102 | +/* test code | |
103 | +int main(int argc, char const *argv[]) { | |
104 | + int count; | |
105 | + cin >> count; | |
106 | + int prime_count = 0; | |
107 | + primer p = primer(20); | |
108 | + mybitset b; | |
109 | + b.setsize(100); | |
110 | + cout << "b.bitlen() = " << b.bitlen() << endl; | |
111 | + for(int i = 0; i < 20; i++){ | |
112 | + b.set(i); | |
113 | + if(!b.get(i)){ | |
114 | + cout << "set error "<< i << endl; | |
115 | + } | |
116 | + } | |
117 | + for(int i = 0; i < 20; i++){ | |
118 | + b.reset(i); | |
119 | + if(b.get(i)){ | |
120 | + cout << "reset error"<< i << endl; | |
121 | + } | |
122 | + } | |
123 | + for(int i = 20; i >= 0; i--){ | |
124 | + b.set(i); | |
125 | + if(!b.get(i)){ | |
126 | + cout << "set error" << i << endl; | |
127 | + } | |
128 | + } | |
129 | + for (int i = 0; i < count; i++) { | |
130 | + int number; | |
131 | + cin >> number; | |
132 | + if (p.getPrime(number)){ | |
133 | + prime_count++; | |
134 | + } | |
135 | + } | |
136 | + cout << prime_count << endl; | |
137 | + return 0; | |
138 | +} | |
139 | +*/ |
@@ -0,0 +1,40 @@ | ||
1 | +#include <iostream> | |
2 | +#include <cassert> | |
3 | + | |
4 | +using namespace std; | |
5 | + | |
6 | +int main(int argc, char const *argv[]) { | |
7 | + int count; | |
8 | + cin >> count; | |
9 | + int *nums = new int[count]; | |
10 | + for (int i = 0; i < count; i++) { | |
11 | + cin >> nums[i]; | |
12 | + } | |
13 | + | |
14 | + assert(count >= 2); | |
15 | + if (count < 2) { | |
16 | + return 1; | |
17 | + } | |
18 | + | |
19 | + int maxprofit = - nums[0]; | |
20 | + int maxprofit_buy = nums[0]; | |
21 | + int min_buy = nums[0]; | |
22 | + | |
23 | + for(int i = 1; i < count; i++){ | |
24 | + int profit = nums[i] - min_buy; | |
25 | + if (maxprofit < profit){ | |
26 | + maxprofit_buy = min_buy; | |
27 | + } | |
28 | + if(nums[i] < min_buy){ | |
29 | + min_buy = nums[i]; | |
30 | + } | |
31 | + profit = nums[i] - maxprofit_buy; | |
32 | + if (maxprofit < profit){ | |
33 | + maxprofit = profit; | |
34 | + } | |
35 | + } | |
36 | + cout << maxprofit << endl; | |
37 | + | |
38 | + delete [] nums; | |
39 | + return 0; | |
40 | +} |
@@ -0,0 +1,13 @@ | ||
1 | +#include <iostream> | |
2 | +#include <cmath> | |
3 | +#include <iomanip> | |
4 | + | |
5 | +using namespace std; | |
6 | + | |
7 | +int main(int argc, char *argv[]){ | |
8 | + long double x1,y1,x2,y2; | |
9 | + cin >> x1 >> y1 >> x2 >> y2; | |
10 | + long double distance = sqrt((x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2)); | |
11 | + cout << fixed << std::setprecision(8) << distance << endl; | |
12 | + return 0; | |
13 | +} |
@@ -0,0 +1,19 @@ | ||
1 | +#include <iostream> | |
2 | +#include <cmath> | |
3 | +#include <iomanip> | |
4 | + | |
5 | +using namespace std; | |
6 | + | |
7 | +int main(int argc, char *argv[]){ | |
8 | + long double a,b,C360; | |
9 | + cin >> a >> b >> C360; | |
10 | + long double C = C360 / 360 * 2 * 3.1415926535897932384626; | |
11 | + long double h = b * sin(C); | |
12 | + long double x = sqrt(b * b + a * a - 2 * a * b * cos(C)); | |
13 | + long double L = a + b + x; | |
14 | + long double S = a * h / 2; | |
15 | + cout << fixed << setprecision(8) << S << endl; | |
16 | + cout << fixed << setprecision(8) << L << endl; | |
17 | + cout << fixed << setprecision(8) << h << endl; | |
18 | + return 0; | |
19 | +} |
@@ -0,0 +1,41 @@ | ||
1 | +#include <iostream> | |
2 | +#include <cmath> | |
3 | +#include <vector> | |
4 | +#include <list> | |
5 | +#include <numeric> | |
6 | + | |
7 | +using namespace std; | |
8 | + | |
9 | +template <template<class T, class Allocator = allocator<T> > class Container> | |
10 | +double mean(Container<double> & x) | |
11 | +{ | |
12 | + return accumulate(x.begin(), x.end(), 0.0) / x.size(); | |
13 | +} | |
14 | +template <template<class T, class Allocator = allocator<T> > class Container> | |
15 | +double var(Container<double> & x) | |
16 | +{ | |
17 | + double size = x.size(); | |
18 | + double x_mean = mean(x); | |
19 | + return (inner_product(x.begin(), x.end(), x.begin(), 0.0) - x_mean * x_mean * size)/ size; | |
20 | +} | |
21 | +template <template<class T, class Allocator = allocator<T> > class Container> | |
22 | +double sd(Container<double> & x) | |
23 | +{ | |
24 | + return sqrt(var(x)); | |
25 | +} | |
26 | +int main() | |
27 | +{ | |
28 | + while(1){ | |
29 | + int count; | |
30 | + cin >> count; | |
31 | + if (count == 0)break; | |
32 | + std::vector<double> x; | |
33 | + for(int i = 0; i < count; i++){ | |
34 | + int s; | |
35 | + cin >> s; | |
36 | + x.push_back(s); | |
37 | + } | |
38 | + cout << sd(x) << endl; | |
39 | + } | |
40 | + return 0; | |
41 | +} |
@@ -0,0 +1,69 @@ | ||
1 | +#include <iostream> | |
2 | +#include <cmath> | |
3 | +#include <vector> | |
4 | +#include <cassert> | |
5 | +#include <iomanip> | |
6 | + | |
7 | +using namespace std; | |
8 | + | |
9 | +int manhattan(vector<int> &x,vector<int> &y){ | |
10 | + assert(x.size() == y.size()); | |
11 | + int sum = 0; | |
12 | + for(int i = 0; i < x.size(); i++){ | |
13 | + sum += abs(x[i] - y[i]); | |
14 | + } | |
15 | + return sum; | |
16 | +} | |
17 | +double euclidean(vector<int> &x, vector<int> &y){ | |
18 | + assert(x.size() == y.size()); | |
19 | + double sum = 0.0; | |
20 | + for(int i = 0; i < x.size(); i++){ | |
21 | + int ab2 = (x[i] - y[i]) * (x[i] - y[i]); | |
22 | + sum += ab2; | |
23 | + } | |
24 | + return sqrt(sum); | |
25 | +} | |
26 | +long double dis_p(int p, vector<int> &x, vector<int> &y){ | |
27 | + assert(x.size() == y.size()); | |
28 | + double sum = 0.0; | |
29 | + for(int i = 0; i < x.size(); i++){ | |
30 | + int ab = abs(x[i] - y[i]); | |
31 | + int ab_p = pow(ab, p); | |
32 | + sum += ab_p; | |
33 | + } | |
34 | + return powl(sum, 1.0L / p); | |
35 | +} | |
36 | +double chebishev(vector<int> &x, vector<int> &y){ | |
37 | + assert(x.size() == y.size()); | |
38 | + double max = 0.0; | |
39 | + for(int i = 0; i < x.size(); i++){ | |
40 | + int ab = abs(x[i] - y[i]); | |
41 | + if(max < ab){ | |
42 | + max = ab; | |
43 | + } | |
44 | + } | |
45 | + return max; | |
46 | +} | |
47 | +void input(int num,vector<int> &v){ | |
48 | + for(int i = 0; i < num; i++){ | |
49 | + int x; | |
50 | + cin >> x; | |
51 | + v.push_back(x); | |
52 | + } | |
53 | +} | |
54 | +void output(long double num){ | |
55 | + cout << fixed << fixed << std::setprecision(8) << num << endl; | |
56 | +} | |
57 | +int main(int argc, char *argv[]) | |
58 | +{ | |
59 | + int num; | |
60 | + cin >> num; | |
61 | + vector<int> x,y; | |
62 | + input(num, x); | |
63 | + input(num, y); | |
64 | + output(manhattan(x,y)); | |
65 | + output (euclidean(x,y)); | |
66 | + output (dis_p(3, x,y)); | |
67 | + output (chebishev(x,y)); | |
68 | + return 0; | |
69 | +} |
@@ -0,0 +1,81 @@ | ||
1 | +#include <iostream> | |
2 | +#include <string> | |
3 | +#include <cassert> | |
4 | + | |
5 | +using namespace std; | |
6 | + | |
7 | +const int DICE_SIZE = 6; | |
8 | + | |
9 | +//ダイス | |
10 | +//東西南北に転がすことができる。 | |
11 | +class dice { | |
12 | + //一番上,南面,東面,西面,北面,底面の数字 | |
13 | + int values[DICE_SIZE]; | |
14 | +public: | |
15 | + dice (); | |
16 | + virtual ~dice (); | |
17 | + int &operator[](int i){ | |
18 | + assert(0 <= i && i < DICE_SIZE); | |
19 | + return values[i]; | |
20 | + }; | |
21 | + void docmd(string str); | |
22 | + void docmd(char c); | |
23 | +private: | |
24 | + int indexs[4][4]; | |
25 | + char *cmdChar; | |
26 | + void move_forward(int *indexs); | |
27 | +}; | |
28 | +dice::dice(){ | |
29 | + int westindex[4] = {1, 3, 6, 4}; | |
30 | + int northindex[4] = {1, 2, 6, 5}; | |
31 | + cmdChar = new char[4]{'W', 'E', 'N', 'S'}; | |
32 | + for(int i = 0; i < 4; i++){ | |
33 | + indexs[0][i] = westindex[i] - 1;//W | |
34 | + indexs[1][i] = westindex[4 - i - 1] - 1;//E | |
35 | + indexs[2][i] = northindex[i] - 1;//N | |
36 | + indexs[3][i] = northindex[4 - i - 1] - 1;//S | |
37 | + } | |
38 | +} | |
39 | +dice::~dice(){ | |
40 | + delete [] cmdChar; | |
41 | +} | |
42 | + | |
43 | +void dice::docmd(string str){ | |
44 | + for(int i = 0; i < str.length(); i++){ | |
45 | + // cout << "docmd(str[i])" << str[i] << endl; | |
46 | + docmd(str[i]); | |
47 | + } | |
48 | +} | |
49 | + | |
50 | +void dice::docmd(char c){ | |
51 | + for(int i = 0; i < 4; i++){ | |
52 | + if (c == cmdChar[i]){ | |
53 | + // cout << cmdChar[i] << endl; | |
54 | + move_forward(indexs[i]); | |
55 | + return; | |
56 | + } | |
57 | + } | |
58 | + assert(false);//命令表にない命令 | |
59 | +} | |
60 | +void dice::move_forward(int *indexs){ | |
61 | + int temp = values[indexs[0]]; | |
62 | + values[indexs[0]] = values[indexs[1]]; | |
63 | + values[indexs[1]] = values[indexs[2]]; | |
64 | + values[indexs[2]] = values[indexs[3]]; | |
65 | + values[indexs[3]] = temp; | |
66 | +} | |
67 | + | |
68 | +int main(int argc, char const *argv[]) { | |
69 | + dice d; | |
70 | + for(int i=0; i < DICE_SIZE; i++){ | |
71 | + int n; | |
72 | + cin >> n; | |
73 | + d[i] = n; | |
74 | + } | |
75 | + string commandstr; | |
76 | + cin >> commandstr; | |
77 | + d.docmd(commandstr); | |
78 | + int topnum = d[0]; | |
79 | + cout << topnum << endl; | |
80 | + return 0; | |
81 | +} |
@@ -0,0 +1,118 @@ | ||
1 | +#include <iostream> | |
2 | +#include <string> | |
3 | +#include <cassert> | |
4 | + | |
5 | +using namespace std; | |
6 | + | |
7 | +const int DICE_SIZE = 6; | |
8 | +int const CmdCount = 6; | |
9 | +int const RotateLen = 4; | |
10 | + | |
11 | +//ダイス | |
12 | +//東西南北に転がすことができる。 | |
13 | +class dice { | |
14 | + //一番上,南面,東面,西面,北面,底面の数字 | |
15 | + int values[DICE_SIZE]; | |
16 | +public: | |
17 | + dice (); | |
18 | + virtual ~dice (); | |
19 | + int &operator[](int i){ | |
20 | + assert(0 <= i && i < DICE_SIZE); | |
21 | + return values[i]; | |
22 | + }; | |
23 | + void docmd(string str); | |
24 | + void docmd(char c); | |
25 | + void setTopAndFront(int top,int front); | |
26 | + void input(void); | |
27 | + int right(void){return values[2];}; | |
28 | + int top(void){return values[0];}; | |
29 | + int front(void){return values[1];}; | |
30 | +private: | |
31 | + | |
32 | + int indexs[CmdCount][RotateLen]; | |
33 | + char *cmdChar; | |
34 | + string *toTopCmd; | |
35 | + string *toFrontCmd; | |
36 | + void move_forward(int *indexs); | |
37 | + int find_value(int num); | |
38 | +}; | |
39 | +void dice::setTopAndFront(int top, int front){ | |
40 | + int idxTop = find_value(top); | |
41 | + docmd(toTopCmd[idxTop]); | |
42 | + int idxFront = find_value(front); | |
43 | + docmd(toFrontCmd[idxFront]); | |
44 | +} | |
45 | +int dice::find_value(int num){ | |
46 | + for(int i = 0; i < DICE_SIZE; i++){ | |
47 | + if(values[i] == num){ | |
48 | + return i; | |
49 | + } | |
50 | + } | |
51 | + assert(false); | |
52 | +} | |
53 | +dice::dice(){ | |
54 | + int westindex[RotateLen] = {1, 3, 6, 4}; | |
55 | + int northindex[RotateLen] = {1, 2, 6, 5}; | |
56 | + int leftindex[RotateLen] = {4, 2, 3, 5}; | |
57 | + cmdChar = new char[CmdCount]{'W', 'E', 'N', 'S','L','R'}; | |
58 | + for(int i = 0; i < RotateLen; i++){ | |
59 | + indexs[0][i] = westindex[i] - 1;//W | |
60 | + indexs[1][i] = westindex[RotateLen - i - 1] - 1;//E | |
61 | + indexs[2][i] = northindex[i] - 1;//N | |
62 | + indexs[3][i] = northindex[RotateLen - i - 1] - 1;//S | |
63 | + indexs[4][i] = leftindex[i] - 1;//L | |
64 | + indexs[5][i] = leftindex[RotateLen - i - 1] - 1;//R | |
65 | + } | |
66 | + toTopCmd = new string[DICE_SIZE]{"","N","W","E","S","NN"}; | |
67 | + toFrontCmd = new string[DICE_SIZE]{"S","","L","R","LL","N"}; | |
68 | +} | |
69 | +dice::~dice(){ | |
70 | + delete [] cmdChar; | |
71 | + delete [] toTopCmd; | |
72 | + delete [] toFrontCmd; | |
73 | +} | |
74 | + | |
75 | +void dice::docmd(string str){ | |
76 | + for(int i = 0; i < str.length(); i++){ | |
77 | + // cout << "docmd(str[i])" << str[i] << endl; | |
78 | + docmd(str[i]); | |
79 | + } | |
80 | +} | |
81 | + | |
82 | +void dice::docmd(char c){ | |
83 | + for(int i = 0; i < CmdCount; i++){ | |
84 | + if (c == cmdChar[i]){ | |
85 | + // cout << cmdChar[i] << endl; | |
86 | + move_forward(indexs[i]); | |
87 | + return; | |
88 | + } | |
89 | + } | |
90 | + assert(false);//命令表にない命令 | |
91 | +} | |
92 | +void dice::move_forward(int *indexs){ | |
93 | + int temp = values[indexs[0]]; | |
94 | + values[indexs[0]] = values[indexs[1]]; | |
95 | + values[indexs[1]] = values[indexs[2]]; | |
96 | + values[indexs[2]] = values[indexs[3]]; | |
97 | + values[indexs[3]] = temp; | |
98 | +} | |
99 | +void dice::input(void){ | |
100 | + for(int i=0; i < DICE_SIZE; i++){ | |
101 | + int n; | |
102 | + cin >> n; | |
103 | + values[i] = n; | |
104 | + } | |
105 | +} | |
106 | +int main(int argc, char const *argv[]) { | |
107 | + dice d; | |
108 | + d.input(); | |
109 | + int count; | |
110 | + cin >> count; | |
111 | + for(int i = 0; i < count ;i++){ | |
112 | + int top,front; | |
113 | + cin >> top >> front; | |
114 | + d.setTopAndFront(top,front); | |
115 | + cout << "right:" << d.right() << "top:" << d.top() << "front:" << d.front() << endl; | |
116 | + } | |
117 | + return 0; | |
118 | +} |
@@ -0,0 +1,141 @@ | ||
1 | +#include <iostream> | |
2 | +#include <string> | |
3 | +#include <cassert> | |
4 | + | |
5 | +using namespace std; | |
6 | + | |
7 | +const int DICE_SIZE = 6; | |
8 | +int const CmdCount = 6; | |
9 | +int const RotateLen = 4; | |
10 | + | |
11 | +//ダイス | |
12 | +//東西南北に転がすことができる。 | |
13 | +class dice { | |
14 | + //一番上,南面,東面,西面,北面,底面の数字 | |
15 | + int values[DICE_SIZE]; | |
16 | +public: | |
17 | + dice (){}; | |
18 | + dice (const dice &d); | |
19 | + virtual ~dice (){}; | |
20 | + int &operator[](int i){ | |
21 | + assert(0 <= i && i < DICE_SIZE); | |
22 | + return values[i]; | |
23 | + }; | |
24 | + void docmd(string str); | |
25 | + void docmd(char c); | |
26 | + void setTopAndFront(int top,int front); | |
27 | + void input(void); | |
28 | + int right(void){return values[2];}; | |
29 | + int top(void){return values[0];}; | |
30 | + int front(void){return values[1];}; | |
31 | + bool Equal(const dice &d); | |
32 | +private: | |
33 | + void output(); | |
34 | + bool IsArrayEqual(const dice &d); | |
35 | + int indexs[CmdCount][RotateLen] = { | |
36 | + {0, 2, 5, 3}, | |
37 | + {3, 5, 2, 0}, | |
38 | + {0, 1, 5, 4}, | |
39 | + {4, 5, 1, 0}, | |
40 | + {3, 1, 2, 4}, | |
41 | + {4, 2, 1, 3}}; | |
42 | + char cmdChar[CmdCount] = {'W', 'E', 'N', 'S','L','R'}; | |
43 | + string toTopCmd[6] = {"","N","W","E","S","NN"}; | |
44 | + string toFrontCmd[6] = {"S","","L","R","LL","N"}; | |
45 | + void move_forward(int *indexs); | |
46 | + int find_value(int num); | |
47 | +}; | |
48 | +dice::dice(const dice &d){ | |
49 | + for(int i = 0; i < DICE_SIZE; i++){ | |
50 | + this->values[i] = d.values[i]; | |
51 | + } | |
52 | +} | |
53 | +void dice::setTopAndFront(int top, int front){ | |
54 | + int idxTop = find_value(top); | |
55 | + docmd(toTopCmd[idxTop]); | |
56 | + int idxFront = find_value(front); | |
57 | + docmd(toFrontCmd[idxFront]); | |
58 | +} | |
59 | +int dice::find_value(int num){ | |
60 | + for(int i = 0; i < DICE_SIZE; i++){ | |
61 | + if(values[i] == num){ | |
62 | + return i; | |
63 | + } | |
64 | + } | |
65 | + assert(false); | |
66 | +} | |
67 | + | |
68 | + | |
69 | +void dice::docmd(string str){ | |
70 | + for(int i = 0; i < str.length(); i++){ | |
71 | + //cout << "docmd(str[i])" << str[i] << endl; | |
72 | + docmd(str[i]); | |
73 | + } | |
74 | +} | |
75 | + | |
76 | +void dice::docmd(char c){ | |
77 | + for(int i = 0; i < CmdCount; i++){ | |
78 | + if (c == cmdChar[i]){ | |
79 | + //cout << cmdChar[i]; | |
80 | + move_forward(indexs[i]); | |
81 | + return; | |
82 | + } | |
83 | + } | |
84 | + assert(false);//命令表にない命令 | |
85 | +} | |
86 | +void dice::move_forward(int *indexs){ | |
87 | + //for(int i = 0; i < 4; i++)cout << indexs[i]; | |
88 | + int temp = values[indexs[0]]; | |
89 | + values[indexs[0]] = values[indexs[1]]; | |
90 | + values[indexs[1]] = values[indexs[2]]; | |
91 | + values[indexs[2]] = values[indexs[3]]; | |
92 | + values[indexs[3]] = temp; | |
93 | +} | |
94 | +void dice::input(void){ | |
95 | + for(int i=0; i < DICE_SIZE; i++){ | |
96 | + int n; | |
97 | + cin >> n; | |
98 | + values[i] = n; | |
99 | + } | |
100 | +} | |
101 | +bool dice::Equal(const dice &d){ | |
102 | + output(); | |
103 | + for(int i = 0; i < DICE_SIZE; i++){ | |
104 | + dice d2 = d; | |
105 | + d2.docmd(toTopCmd[i]); | |
106 | + for(int j = 0; j < RotateLen; j++){ | |
107 | + d2.docmd('L'); | |
108 | + // cout << "d2 is "; | |
109 | + d2.output(); | |
110 | + if (IsArrayEqual(d2)){ | |
111 | + return true; | |
112 | + } | |
113 | + } | |
114 | + } | |
115 | + return false; | |
116 | +} | |
117 | +void dice::output(){ | |
118 | +/* for(int i=0;i<DICE_SIZE;i++){ | |
119 | + cout << values[i] << " "; | |
120 | + } | |
121 | + cout << endl;*/ | |
122 | +} | |
123 | +bool dice::IsArrayEqual(const dice &d){ | |
124 | + for (int i = 0; i < DICE_SIZE; i++) { | |
125 | + if (d.values[i] != this->values[i]){ | |
126 | + return false; | |
127 | + } | |
128 | + } | |
129 | + return true; | |
130 | +} | |
131 | +int main(int argc, char const *argv[]) { | |
132 | + dice d1,d2; | |
133 | + d1.input(); | |
134 | + d2.input(); | |
135 | + if (d1.Equal(d2)){ | |
136 | + cout << "Yes" << endl; | |
137 | + }else{ | |
138 | + cout << "No" << endl; | |
139 | + } | |
140 | + return 0; | |
141 | +} |
@@ -0,0 +1,21 @@ | ||
1 | +#include <iostream> | |
2 | +using namespace std; | |
3 | + | |
4 | +class cls{ | |
5 | +public: | |
6 | + cls(); | |
7 | + cls(const cls &c); | |
8 | +}; | |
9 | + | |
10 | +cls::cls(){ | |
11 | + cout << "cls::cls\n"; | |
12 | +} | |
13 | +cls::cls(const cls &c){ | |
14 | + cout << "cls::cls(cls c)\n"; | |
15 | +} | |
16 | + | |
17 | +int main(int argc, char *argv[]){ | |
18 | + cls c1; | |
19 | + cls c2 = c1; | |
20 | + return 0; | |
21 | +} |
@@ -0,0 +1,151 @@ | ||
1 | +#include <iostream> | |
2 | +#include <string> | |
3 | +#include <cassert> | |
4 | + | |
5 | +using namespace std; | |
6 | + | |
7 | +const int DICE_SIZE = 6; | |
8 | +int const CmdCount = 6; | |
9 | +int const RotateLen = 4; | |
10 | + | |
11 | +//ダイス | |
12 | +//東西南北に転がすことができる。 | |
13 | +class dice { | |
14 | + //一番上,南面,東面,西面,北面,底面の数字 | |
15 | + int values[DICE_SIZE]; | |
16 | +public: | |
17 | + dice (){}; | |
18 | + dice (const dice &d); | |
19 | + virtual ~dice (){}; | |
20 | + int &operator[](int i){ | |
21 | + assert(0 <= i && i < DICE_SIZE); | |
22 | + return values[i]; | |
23 | + }; | |
24 | + void docmd(string str); | |
25 | + void docmd(char c); | |
26 | + void setTopAndFront(int top,int front); | |
27 | + void input(void); | |
28 | + int right(void){return values[2];}; | |
29 | + int top(void){return values[0];}; | |
30 | + int front(void){return values[1];}; | |
31 | + bool Equal(const dice &d); | |
32 | +private: | |
33 | + void output(); | |
34 | + bool IsArrayEqual(const dice &d); | |
35 | + int indexs[CmdCount][RotateLen] = { | |
36 | + {0, 2, 5, 3}, | |
37 | + {3, 5, 2, 0}, | |
38 | + {0, 1, 5, 4}, | |
39 | + {4, 5, 1, 0}, | |
40 | + {3, 1, 2, 4}, | |
41 | + {4, 2, 1, 3}}; | |
42 | + char cmdChar[CmdCount] = {'W', 'E', 'N', 'S','L','R'}; | |
43 | + string toTopCmd[6] = {"","N","W","E","S","NN"}; | |
44 | + string toFrontCmd[6] = {"S","","L","R","LL","N"}; | |
45 | + void move_forward(int *indexs); | |
46 | + int find_value(int num); | |
47 | +}; | |
48 | +dice::dice(const dice &d){ | |
49 | + for(int i = 0; i < DICE_SIZE; i++){ | |
50 | + this->values[i] = d.values[i]; | |
51 | + } | |
52 | +} | |
53 | +void dice::setTopAndFront(int top, int front){ | |
54 | + int idxTop = find_value(top); | |
55 | + docmd(toTopCmd[idxTop]); | |
56 | + int idxFront = find_value(front); | |
57 | + docmd(toFrontCmd[idxFront]); | |
58 | +} | |
59 | +int dice::find_value(int num){ | |
60 | + for(int i = 0; i < DICE_SIZE; i++){ | |
61 | + if(values[i] == num){ | |
62 | + return i; | |
63 | + } | |
64 | + } | |
65 | + assert(false); | |
66 | +} | |
67 | + | |
68 | + | |
69 | +void dice::docmd(string str){ | |
70 | + for(int i = 0; i < str.length(); i++){ | |
71 | + //cout << "docmd(str[i])" << str[i] << endl; | |
72 | + docmd(str[i]); | |
73 | + } | |
74 | +} | |
75 | + | |
76 | +void dice::docmd(char c){ | |
77 | + for(int i = 0; i < CmdCount; i++){ | |
78 | + if (c == cmdChar[i]){ | |
79 | + //cout << cmdChar[i]; | |
80 | + move_forward(indexs[i]); | |
81 | + return; | |
82 | + } | |
83 | + } | |
84 | + assert(false);//命令表にない命令 | |
85 | +} | |
86 | +void dice::move_forward(int *indexs){ | |
87 | + //for(int i = 0; i < 4; i++)cout << indexs[i]; | |
88 | + int temp = values[indexs[0]]; | |
89 | + values[indexs[0]] = values[indexs[1]]; | |
90 | + values[indexs[1]] = values[indexs[2]]; | |
91 | + values[indexs[2]] = values[indexs[3]]; | |
92 | + values[indexs[3]] = temp; | |
93 | +} | |
94 | +void dice::input(void){ | |
95 | + for(int i=0; i < DICE_SIZE; i++){ | |
96 | + int n; | |
97 | + cin >> n; | |
98 | + values[i] = n; | |
99 | + } | |
100 | +} | |
101 | +bool dice::Equal(const dice &d){ | |
102 | + output(); | |
103 | + for(int i = 0; i < DICE_SIZE; i++){ | |
104 | + dice d2 = d; | |
105 | + d2.docmd(toTopCmd[i]); | |
106 | + for(int j = 0; j < RotateLen; j++){ | |
107 | + d2.docmd('L'); | |
108 | + // cout << "d2 is "; | |
109 | + d2.output(); | |
110 | + if (IsArrayEqual(d2)){ | |
111 | + return true; | |
112 | + } | |
113 | + } | |
114 | + } | |
115 | + return false; | |
116 | +} | |
117 | +void dice::output(){ | |
118 | +/* for(int i=0;i<DICE_SIZE;i++){ | |
119 | + cout << values[i] << " "; | |
120 | + } | |
121 | + cout << endl;*/ | |
122 | +} | |
123 | +bool dice::IsArrayEqual(const dice &d){ | |
124 | + for (int i = 0; i < DICE_SIZE; i++) { | |
125 | + if (d.values[i] != this->values[i]){ | |
126 | + return false; | |
127 | + } | |
128 | + } | |
129 | + return true; | |
130 | +} | |
131 | +int main(int argc, char const *argv[]) { | |
132 | + int count; | |
133 | + cin >> count; | |
134 | + dice dice_array = new dice[count]; | |
135 | + for(int i = 0; i < count; i++){ | |
136 | + dice_array[i].input(); | |
137 | + } | |
138 | + bool isALLEqual = true; | |
139 | + for(int i = 1; i < count ;i++){ | |
140 | + if(!dice_array[i].Equal(dice_array[0])){ | |
141 | + isALLEqual = false; | |
142 | + break; | |
143 | + } | |
144 | + } | |
145 | + if (isALLEqual){ | |
146 | + cout << "Yes" << endl; | |
147 | + }else{ | |
148 | + cout << "No" << endl; | |
149 | + } | |
150 | + return 0; | |
151 | +} |
@@ -0,0 +1,17 @@ | ||
1 | +#include <iostream> | |
2 | +using namespace std; | |
3 | + | |
4 | +int main(int argc, char *argv[]) | |
5 | +{ | |
6 | + int a,b; | |
7 | + std::cin >> a >> b; | |
8 | + if (a < b) { | |
9 | + cout << "a < b\n"; | |
10 | + } else if (a > b) { | |
11 | + cout << "a > b\n"; | |
12 | + } else { | |
13 | + cout << "a == b\n"; | |
14 | + } | |
15 | + return 0; | |
16 | +} | |
17 | + |
@@ -0,0 +1,15 @@ | ||
1 | +#include <iostream> | |
2 | +using namespace std; | |
3 | + | |
4 | +int main(int argc, char *argv[]) | |
5 | +{ | |
6 | + int a,b,c; | |
7 | + std::cin >> a >> b >> c; | |
8 | + if (a < b && b < c) { | |
9 | + cout << "Yes\n"; | |
10 | + } else { | |
11 | + cout << "No\n"; | |
12 | + } | |
13 | + return 0; | |
14 | +} | |
15 | + |
@@ -0,0 +1,29 @@ | ||
1 | +#include <iostream> | |
2 | +using namespace std; | |
3 | + | |
4 | +int main(int argc, char *argv[]){ | |
5 | + int const count = 3; | |
6 | + int nums[count]; | |
7 | + //入力 | |
8 | + for(int i = 0; i < count; i++){ | |
9 | + cin >> nums[i]; | |
10 | + } | |
11 | + | |
12 | + //小さい順に並べる | |
13 | + for(int i = 0; i < count - 1; i++){ | |
14 | + for(int j = i + 1; j < count; j++){ | |
15 | + if (nums[i] > nums[j]) { | |
16 | + int temp = nums[i]; | |
17 | + nums[i] = nums[j]; | |
18 | + nums[j] = temp; | |
19 | + } | |
20 | + } | |
21 | + } | |
22 | + | |
23 | + //出力 | |
24 | + for(int i = 0; i < count - 1; i++){ | |
25 | + cout << nums[i] << ' '; | |
26 | + } | |
27 | + cout << nums[count - 1]; | |
28 | + cout << "\n"; | |
29 | +} |
@@ -0,0 +1,16 @@ | ||
1 | +#include <iostream> | |
2 | +using namespace std; | |
3 | + | |
4 | +//長方形内に円が入っているかの判定 | |
5 | + | |
6 | +int main(int argc, char *argv[]){ | |
7 | + int W, H, x, y, r; | |
8 | + bool isOut; | |
9 | + cin >> W >> H >> x >> y >> r; | |
10 | + if (x - r < 0 || x + r > W | |
11 | + || y - r < 0 || y + r > H){ | |
12 | + cout << "No\n"; | |
13 | + } else { | |
14 | + cout << "Yes\n"; | |
15 | + } | |
16 | +} |
@@ -0,0 +1,9 @@ | ||
1 | +#include <iostream> | |
2 | +using namespace std; | |
3 | + | |
4 | +int main(int argc, char *argv[]){ | |
5 | + for(int i = 0; i < 1000; i++){ | |
6 | + cout << "Hello World\n"; | |
7 | + } | |
8 | + return 0; | |
9 | +} |
@@ -0,0 +1,9 @@ | ||
1 | +#include <iostream> | |
2 | +using namespace std; | |
3 | + | |
4 | +int main(int argc, char *argv[]){ | |
5 | + int n,i = 1; | |
6 | + for(cin >> n;n != 0; cin >> n){ | |
7 | + cout << "Case " << i++ << ": " << n << "\n"; | |
8 | + } | |
9 | +} |
@@ -0,0 +1,19 @@ | ||
1 | +#include <iostream> | |
2 | +using namespace std; | |
3 | + | |
4 | +void output(int a, int b){ | |
5 | + cout << a << " " << b << "\n"; | |
6 | +} | |
7 | +int main(int argc, char *argv[]){ | |
8 | + int a,b; | |
9 | + while(1){ | |
10 | + cin >> a >> b; | |
11 | + if (a == 0 && b == 0) break; | |
12 | + if (a < b) { | |
13 | + output(a,b); | |
14 | + } else { | |
15 | + output(b,a); | |
16 | + } | |
17 | + } | |
18 | +} | |
19 | + |
@@ -0,0 +1,13 @@ | ||
1 | +#include <iostream> | |
2 | +using namespace std; | |
3 | + | |
4 | +int main(int argc, char *argv[]){ | |
5 | + int a,b,c; | |
6 | + int count = 0; | |
7 | + cin >> a >> b >> c; | |
8 | + for(int i = a; i <= b; i++){ | |
9 | + if(c % i == 0)count++; | |
10 | + } | |
11 | + cout << count << "\n"; | |
12 | + return 0; | |
13 | +} |
@@ -0,0 +1,14 @@ | ||
1 | +#include <iostream> | |
2 | +using namespace std; | |
3 | + | |
4 | +int main(int argc, char *argv[]){ | |
5 | + int a,b; | |
6 | + int d,r; | |
7 | + double f; | |
8 | + cin >> a >> b; | |
9 | + d = a / b; | |
10 | + r = a % b; | |
11 | + f = (double)a / b; | |
12 | + cout << d << " " << r << " " << fixed << f << "\n"; | |
13 | + return 0; | |
14 | +} |
@@ -0,0 +1,15 @@ | ||
1 | +#include <iostream> | |
2 | +using namespace std; | |
3 | + | |
4 | +int main(int argc, char *argv[]){ | |
5 | + long double r; | |
6 | + long double const PI = 3.141592653589793238L; | |
7 | + | |
8 | + cin >> r; | |
9 | + long double area = PI * r * r; | |
10 | + long double len = 2 * PI * r; | |
11 | + cout << fixed << area << " "; | |
12 | + cout << fixed << len << "\n"; | |
13 | + return 0; | |
14 | +} | |
15 | + |
@@ -0,0 +1,19 @@ | ||
1 | +#include <iostream> | |
2 | +using namespace std; | |
3 | + | |
4 | +int main(int argc, char *argv[]){ | |
5 | + int a,b; | |
6 | + char op; | |
7 | + while(1){ | |
8 | + int ans; | |
9 | + cin >> a >> op >> b; | |
10 | + if (op == '?') break; | |
11 | + if (op == '+') ans = a + b; | |
12 | + if (op == '-') ans = a - b; | |
13 | + if (op == '/') ans = a / b; | |
14 | + if (op == '*') ans = a * b; | |
15 | + cout << ans << "\n"; | |
16 | + } | |
17 | + return 0; | |
18 | +} | |
19 | + |
@@ -0,0 +1,28 @@ | ||
1 | +#include <iostream> | |
2 | +using namespace std; | |
3 | + | |
4 | +int main(int argc,char *argv[]){ | |
5 | + int count; | |
6 | + long int max,min,sum = 0; | |
7 | + long int n; | |
8 | + cin >> count; | |
9 | + if (count--){ | |
10 | + cin >> n; | |
11 | + sum += n; | |
12 | + max = n; | |
13 | + min = n; | |
14 | + } | |
15 | + while(count--){ | |
16 | + cin >> n; | |
17 | + sum += n; | |
18 | + if (max < n) { | |
19 | + max = n; | |
20 | + } | |
21 | + if (min > n) { | |
22 | + min = n; | |
23 | + } | |
24 | + } | |
25 | + cout << min << " " << max << " " << sum << "\n"; | |
26 | + return 0; | |
27 | +} | |
28 | + |
@@ -0,0 +1,18 @@ | ||
1 | +#include <iostream> | |
2 | +using namespace std; | |
3 | + | |
4 | +int main(int argc,char *argv[]){ | |
5 | + int H,W; | |
6 | + while(1) { | |
7 | + cin >> H >> W; | |
8 | + if (H == 0 && W == 0) break; | |
9 | + for(int i = 0; i < H; i++){ | |
10 | + for (int j = 0; j < W; j++){ | |
11 | + cout << "#"; | |
12 | + } | |
13 | + cout << "\n"; | |
14 | + } | |
15 | + cout << "\n"; | |
16 | + } | |
17 | + return 0; | |
18 | +} |
@@ -0,0 +1,22 @@ | ||
1 | +#include <iostream> | |
2 | +using namespace std; | |
3 | + | |
4 | +int main(int argc,char *argv[]){ | |
5 | + int H,W; | |
6 | + while(1) { | |
7 | + cin >> H >> W; | |
8 | + if (H == 0 && W == 0) break; | |
9 | + for(int i = 0; i < H; i++){ | |
10 | + for (int j = 0; j < W; j++){ | |
11 | + if (i == 0 || i == H - 1 || j == 0 || j == W - 1){ | |
12 | + cout << "#"; | |
13 | + } else { | |
14 | + cout << "."; | |
15 | + } | |
16 | + } | |
17 | + cout << "\n"; | |
18 | + } | |
19 | + cout << "\n"; | |
20 | + } | |
21 | + return 0; | |
22 | +} |
@@ -0,0 +1,24 @@ | ||
1 | +#include <iostream> | |
2 | +using namespace std; | |
3 | + | |
4 | +int main(int argc,char *argv[]){ | |
5 | + int H,W; | |
6 | + int count; | |
7 | + while(1) { | |
8 | + cin >> H >> W; | |
9 | + if (H == 0 && W == 0) break; | |
10 | + for(int i = 0; i < H; i++){ | |
11 | + count = i % 2; | |
12 | + for (int j = 0; j < W; j++){ | |
13 | + if (count++ % 2 == 0){ | |
14 | + cout << "#"; | |
15 | + } else { | |
16 | + cout << "."; | |
17 | + } | |
18 | + } | |
19 | + cout << "\n"; | |
20 | + } | |
21 | + cout << "\n"; | |
22 | + } | |
23 | + return 0; | |
24 | +} |
@@ -0,0 +1,31 @@ | ||
1 | +#include <iostream> | |
2 | +using namespace std; | |
3 | +void output(int i){ | |
4 | + cout << " " << i; | |
5 | +} | |
6 | +bool include3(int n){ | |
7 | + while(n){ | |
8 | + if (n % 10 == 3){ | |
9 | + return true; | |
10 | + } | |
11 | + n /= 10; | |
12 | + } | |
13 | + return false; | |
14 | +} | |
15 | +void call(int n){ | |
16 | + for(int i = 1; i <= n; i++){ | |
17 | + if(include3(i)){ | |
18 | + output(i); | |
19 | + }else if(i % 3 == 0){ | |
20 | + output(i); | |
21 | + } | |
22 | + } | |
23 | + cout << endl; | |
24 | +} | |
25 | + | |
26 | +int main(int argc,char *argv[]){ | |
27 | + int n; | |
28 | + cin >> n; | |
29 | + call(n); | |
30 | + return 0; | |
31 | +} |
@@ -0,0 +1,25 @@ | ||
1 | +#include <iostream> | |
2 | +using namespace std; | |
3 | + | |
4 | +int main(int argc, char *argv[]){ | |
5 | + int count; | |
6 | + int nums[100]; | |
7 | + cin >> count; | |
8 | + for(int i = 0; i < count; i++){ | |
9 | + cin >> nums[i]; | |
10 | + } | |
11 | + if (count > 0){ | |
12 | + cout << nums[count - 1]; | |
13 | + } | |
14 | + | |
15 | + for(int i = count - 1; i > 0; i--){ | |
16 | + cout << " " << nums[i - 1]; | |
17 | + } | |
18 | + cout << endl; | |
19 | + return 0; | |
20 | +} | |
21 | + | |
22 | + | |
23 | + | |
24 | + | |
25 | + |
@@ -0,0 +1,42 @@ | ||
1 | +#include <iostream> | |
2 | + | |
3 | +using namespace std; | |
4 | +int const CARD_NUM = 13; | |
5 | +int const TYPE_NUM = 4; | |
6 | +int const CARD_TOTAL_NUM = CARD_NUM * TYPE_NUM; | |
7 | +char const CARD_TYPES[TYPE_NUM] = {'S','H','C','D'}; | |
8 | + | |
9 | +void output(int card){ | |
10 | + int cardtype = card / CARD_NUM; | |
11 | + int cardnum = (card % CARD_NUM) + 1; | |
12 | + cout << CARD_TYPES[cardtype] << " " << cardnum << "\n"; | |
13 | +} | |
14 | +int input(){ | |
15 | + char cardtype; | |
16 | + int cardnum; | |
17 | + cin >> cardtype >> cardnum; | |
18 | + for(int i = 0; i < TYPE_NUM; i++){ | |
19 | + if(CARD_TYPES[i] == cardtype) { | |
20 | + return i * CARD_NUM + cardnum - 1; | |
21 | + } | |
22 | + } | |
23 | + return 0;//失敗 | |
24 | +} | |
25 | +int main(int argc, char *argv[]){ | |
26 | + int isExistCard[CARD_TOTAL_NUM]; | |
27 | + for(int i = 0; i < CARD_TOTAL_NUM; i++){ | |
28 | + isExistCard[i] = false; | |
29 | + } | |
30 | + int existNum; | |
31 | + cin >> existNum; | |
32 | + for(int i = 0; i < existNum; i++){ | |
33 | + int card = input(); | |
34 | + isExistCard[card] = true; | |
35 | + } | |
36 | + for(int i = 0; i < CARD_TOTAL_NUM; i++){ | |
37 | + if (!isExistCard[i]){ | |
38 | + output(i); | |
39 | + } | |
40 | + } | |
41 | + return 0; | |
42 | +} |
@@ -0,0 +1,37 @@ | ||
1 | +#include <iostream> | |
2 | + | |
3 | +using namespace std; | |
4 | + | |
5 | +int main(int argc, char *argv[]){ | |
6 | + //初期化 | |
7 | + int num_of_people[4][3][10]; | |
8 | + for(int i = 0; i < 4; i++){ | |
9 | + for(int j = 0; j < 3; j++){ | |
10 | + for(int k = 0; k < 10; k++){ | |
11 | + num_of_people[i][j][k] = 0; | |
12 | + } | |
13 | + } | |
14 | + } | |
15 | + //入力 | |
16 | + int count; | |
17 | + cin >> count; | |
18 | + for(int i = 0; i < count; i++){ | |
19 | + int b,f,r,v; | |
20 | + cin >> b >> f >> r >> v; | |
21 | + num_of_people[b - 1][f - 1][r - 1] += v; | |
22 | + } | |
23 | + //出力 | |
24 | + for (int i = 0; i < 4; i++){ | |
25 | + for(int j = 0; j < 3; j++){ | |
26 | + for(int k = 0; k < 10; k++){ | |
27 | + cout << " " << num_of_people[i][j][k]; | |
28 | + if (k == 10 - 1){ | |
29 | + cout << "\n"; | |
30 | + } | |
31 | + } | |
32 | + } | |
33 | + if (i != 4 - 1){ | |
34 | + cout << "####################\n"; | |
35 | + } | |
36 | + } | |
37 | +} |
@@ -0,0 +1,43 @@ | ||
1 | +#include <iostream> | |
2 | + | |
3 | +using namespace std; | |
4 | + | |
5 | +int main(int argc,char *argv[]){ | |
6 | + int m,n; | |
7 | + int *b; | |
8 | + int **A; | |
9 | + int *c; | |
10 | + cin >> n >> m; | |
11 | + A = new int*[n]; | |
12 | + for(int i=0; i < n; i++){ | |
13 | + A[i] = new int[m]; | |
14 | + } | |
15 | + for(int i=0; i < n; i++){ | |
16 | + for(int j=0; j < m;j++){ | |
17 | + cin >> A[i][j]; | |
18 | + } | |
19 | + } | |
20 | + b = new int[m]; | |
21 | + for(int i=0; i < m; i++){ | |
22 | + cin >> b[i]; | |
23 | + } | |
24 | + c = new int[n]; | |
25 | + for(int i=0; i < n; i++){ | |
26 | + c[i] = 0; | |
27 | + for(int j=0; j < m; j++){ | |
28 | + c[i] += A[i][j] * b[j]; | |
29 | + // cout << " + " <<A[i][j] << "*" << b[j]; | |
30 | + } | |
31 | + //cout << "=" << c[i] << endl; | |
32 | + cout << c[i] << endl; | |
33 | + } | |
34 | + delete[] c; | |
35 | + | |
36 | + delete[] b; | |
37 | + for(int i=0; i < n; i++){ | |
38 | + delete[] A[i]; | |
39 | + } | |
40 | + delete[] A; | |
41 | + | |
42 | + return 0; | |
43 | +} |
@@ -0,0 +1,59 @@ | ||
1 | +#include <iostream> | |
2 | +using namespace std; | |
3 | + | |
4 | +class student { | |
5 | + int m; | |
6 | + int f; | |
7 | + int r; | |
8 | +public: | |
9 | + student(int m,int f, int r); | |
10 | + char grade(); | |
11 | + bool isempty(); | |
12 | +}; | |
13 | + | |
14 | +student::student(int m, int f, int r){ | |
15 | + this->m = m; | |
16 | + this->f = f; | |
17 | + this->r = r; | |
18 | +} | |
19 | + | |
20 | +char student::grade(){ | |
21 | + if (m == -1 || f == -1){ | |
22 | + return 'F'; | |
23 | + } | |
24 | + if (m + f >= 80) { | |
25 | + return 'A'; | |
26 | + } | |
27 | + if (m + f >= 65){ | |
28 | + return 'B'; | |
29 | + } | |
30 | + if (m + f >= 50){ | |
31 | + return 'C'; | |
32 | + } | |
33 | + if (m + f >= 30){ | |
34 | + if (r >= 50){ | |
35 | + return 'C'; | |
36 | + } | |
37 | + return 'D'; | |
38 | + } | |
39 | + return 'F'; | |
40 | +} | |
41 | + | |
42 | +bool student::isempty(){ | |
43 | + return m == -1 && f == -1 && r == -1; | |
44 | +} | |
45 | + | |
46 | +int main(int argc,char *argv[]){ | |
47 | + student *s; | |
48 | + while(1){ | |
49 | + int m,f,r; | |
50 | + cin >> m >> f >> r; | |
51 | + s = new student(m, f, r); | |
52 | + if (s->isempty()){ | |
53 | + break; | |
54 | + } | |
55 | + cout << s->grade() << endl; | |
56 | + delete s; | |
57 | + } | |
58 | + return 0; | |
59 | +} |
@@ -0,0 +1,22 @@ | ||
1 | +#include <iostream> | |
2 | +#include <string> | |
3 | +#include <algorithm> | |
4 | +#include <cstdlib> | |
5 | + | |
6 | +using namespace std; | |
7 | + | |
8 | +char char_shift(char c){ | |
9 | + if (islower(c)){ | |
10 | + return toupper(c); | |
11 | + } | |
12 | + return tolower(c); | |
13 | +} | |
14 | + | |
15 | +int main(int argc,char *argv[]){ | |
16 | + char buf[1200]; | |
17 | + cin.getline(buf, sizeof(buf)); | |
18 | + string str = buf; | |
19 | + transform(str.begin(), str.end(), str.begin(), char_shift); | |
20 | + cout << str << endl; | |
21 | +} | |
22 | + |
@@ -0,0 +1,23 @@ | ||
1 | +#include <iostream> | |
2 | +using namespace std; | |
3 | + | |
4 | +int sum(char *buf){ | |
5 | + char *p = buf; | |
6 | + int sum = 0; | |
7 | + while(*p != 0){ | |
8 | + if('0' <= *p && *p <= '9'){ | |
9 | + sum += *p - '0'; | |
10 | + } | |
11 | + p++; | |
12 | + } | |
13 | + return sum; | |
14 | +} | |
15 | + | |
16 | +int main(int argc, char *argv[]){ | |
17 | + char buf[1000+2]; | |
18 | + while(1){ | |
19 | + cin.getline(buf,sizeof(buf)); | |
20 | + if (buf[0] == '0')break; | |
21 | + cout << sum(buf) << endl; | |
22 | + } | |
23 | +} |
@@ -0,0 +1,20 @@ | ||
1 | +#include <iostream> | |
2 | +using namespace std; | |
3 | + | |
4 | +int main(int argc, char *argv[]){ | |
5 | + int count['z' - 'a' + 1]; | |
6 | + for(char c = 'a'; c <= 'z'; c++){ | |
7 | + count[c - 'a'] = 0; | |
8 | + } | |
9 | + while(!cin.eof()){ | |
10 | + char c = cin.get(); | |
11 | + if ('A' <= c && c <= 'Z'){ | |
12 | + count[c - 'A']++; | |
13 | + } else if ('a' <= c && c <= 'z'){ | |
14 | + count[c - 'a']++; | |
15 | + } | |
16 | + } | |
17 | + for(char c = 'a';c <= 'z'; c++){ | |
18 | + cout << c << " : " << count[c - 'a'] << endl; | |
19 | + } | |
20 | +} |
@@ -0,0 +1,20 @@ | ||
1 | +#include <iostream> | |
2 | +#include <string> | |
3 | + | |
4 | +using namespace std; | |
5 | + | |
6 | +int main(int argc, char *argv[]){ | |
7 | + string s; | |
8 | + string p; | |
9 | + getline(cin, s); | |
10 | + getline(cin, p); | |
11 | + string s2 = s + s; | |
12 | + if (s2.find(p) == string::npos){ | |
13 | + cout << "No\n"; | |
14 | + } else { | |
15 | + cout << "Yes\n"; | |
16 | + } | |
17 | + return 0; | |
18 | +} | |
19 | + | |
20 | + |
@@ -0,0 +1,30 @@ | ||
1 | +#include <iostream> | |
2 | +#include <string> | |
3 | +#include <cstdlib> | |
4 | +#include <algorithm> | |
5 | + | |
6 | +using namespace std; | |
7 | + | |
8 | +char ToLower(char c){ | |
9 | + return tolower(c); | |
10 | +} | |
11 | + | |
12 | +void tolower(string &s){ | |
13 | + transform(s.begin(), s.end(), s.begin(), ToLower); | |
14 | +} | |
15 | + | |
16 | +int main(int argc, char *argv[]){ | |
17 | + string W; | |
18 | + string Ti; | |
19 | + getline(cin, W); | |
20 | + tolower(W); | |
21 | + int count = 0; | |
22 | + while(1){ | |
23 | + cin >> Ti; | |
24 | + if(Ti == "END_OF_TEXT")break; | |
25 | + tolower(Ti); | |
26 | + if(Ti == W)count++; | |
27 | + } | |
28 | + cout << count << endl; | |
29 | + return 0; | |
30 | +} |
@@ -0,0 +1,25 @@ | ||
1 | +#include <iostream> | |
2 | +#include <string> | |
3 | + | |
4 | +using namespace std; | |
5 | + | |
6 | +int main(int argc, char *argv[]){ | |
7 | + | |
8 | + while(1){ | |
9 | + string inputstr; | |
10 | + //getline(cin, inputstr); | |
11 | + cin >> inputstr; | |
12 | + if(inputstr == "-")break; | |
13 | + int count; | |
14 | + cin >> count; | |
15 | + string s = inputstr; | |
16 | + for(int i= 0; i< count; i++){ | |
17 | + int h; | |
18 | + cin >> h; | |
19 | + int len = s.length(); | |
20 | + s = s.substr(h , len - h) + s.substr(0, h); | |
21 | + } | |
22 | + cout << s << endl; | |
23 | + } | |
24 | + return 0; | |
25 | +} |
@@ -0,0 +1,25 @@ | ||
1 | +#include <iostream> | |
2 | +#include <string> | |
3 | + | |
4 | +using namespace std; | |
5 | + | |
6 | +int main(int argc, char *argv[]){ | |
7 | + int n; | |
8 | + cin >> n; | |
9 | + string s_hanako, s_taro; | |
10 | + int p_hanako = 0; | |
11 | + int p_taro = 0; | |
12 | + for(int i = 0; i < n; i++){ | |
13 | + cin >> s_taro >> s_hanako; | |
14 | + if (s_taro == s_hanako){ | |
15 | + p_hanako += 1; | |
16 | + p_taro += 1; | |
17 | + } else if (s_taro < s_hanako) { | |
18 | + p_hanako += 3; | |
19 | + } else if (s_taro > s_hanako) { | |
20 | + p_taro += 3; | |
21 | + } | |
22 | + } | |
23 | + cout << p_taro << " " << p_hanako << endl; | |
24 | + return 0; | |
25 | +} |
@@ -0,0 +1,31 @@ | ||
1 | +#include <iostream> | |
2 | +#include <string> | |
3 | +#include <algorithm> | |
4 | + | |
5 | +using namespace std; | |
6 | + | |
7 | +int main(int argc, char *argv[]){ | |
8 | + string str; | |
9 | + cin >> str; | |
10 | + int count; | |
11 | + cin >> count; | |
12 | + for(int i = 0; i < count; i++){ | |
13 | + string command; | |
14 | + cin >> command; | |
15 | + if (command == "replace"){ | |
16 | + int first,last; | |
17 | + string replace_str; | |
18 | + cin >> first >> last >> replace_str; | |
19 | + str.replace(first, last - first + 1, replace_str); | |
20 | + }else if(command == "reverse"){ | |
21 | + int first,last; | |
22 | + cin >> first >> last; | |
23 | + reverse(str.begin() + first, str.begin() + last + 1); | |
24 | + }else if(command == "print"){ | |
25 | + int first, last; | |
26 | + cin >> first >> last; | |
27 | + cout << str.substr(first,last - first + 1) << endl; | |
28 | + } | |
29 | + } | |
30 | + return 0; | |
31 | +} | |
\ No newline at end of file |
@@ -0,0 +1,11 @@ | ||
1 | +#include <iostream> | |
2 | +#include <string> | |
3 | +#include <algorithm> | |
4 | + | |
5 | +using namespace std; | |
6 | + | |
7 | +int main(int argc, char *argv[]){ | |
8 | + string str = "abcde"; | |
9 | + reverse(str.begin(), str.end()); | |
10 | + cout << str << endl; | |
11 | +} |