[Coding] SWEA 1984, 2050 C++

๋ฌธ์ฑ„์˜ยท2023๋…„ 5์›” 4์ผ
0

๐Ÿ’ป1984

๋ฐ˜์˜ฌ๋ฆผ: ํ—ค๋” cmath, round(๊ฐ’)
sort: ํ—ค๋” algorithm, sort(arr,arr+ํฌ๊ธฐ)

#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;

int main(int argc, char** argv)
{
	int test_case;
	int T;
	cin>>T;
	
	for(test_case = 1; test_case <= T; ++test_case)
	{

		int arr[10];
		double sum=0;
        for(int i=0;i<10;i++){
            cin>>arr[i];
        }
		sort(arr,arr+10);
		for(int i=1;i<=8;i++){
            sum+=arr[i];
        }
        cout<<"#"<<test_case<<" "<<round(sum/8)<<"\n";
	}
    

	return 0;
}

๐Ÿ’ป2050

๋Œ€๋ฌธ์ž ABC... ๋ฅผ 1,2,3์œผ๋กœ ๋ฐ”๊ฟ” ์ถœ๋ ฅํ•˜๊ธฐ

#include<iostream>
#include<string>
using namespace std;

int main() {
	string input;
	cin >> input;

	for (int i = 0; i < input.length(); i++) {
		int a = input[i]  -64;
		cout << a << " ";
	}
	
}

์‘์šฉ: ๋Œ€, ์†Œ ๋ฌธ์ž abc๋ฅผ 1,2,3,,์œผ๋กœ ์ถœ๋ ฅํ•˜๊ธฐ

#include<iostream>
#include<string>
using namespace std;

int main() {
	string input;
	cin >> input;

	for (int i = 0; i < input.length(); i++) {
		int a;
		if (input[i] - 0 > 64 && input[i]-0 < 91) {
			 a = input[i] - 64;
		}
		else if (input[i] - 0 > 96 && input[i] - 0 < 123) {
			 a = input[i] - 96;
		}
		cout << a << " ";
	}

}

0๊ฐœ์˜ ๋Œ“๊ธ€