728x90
// Create keyed object from array
// importance: 4
// Let’s say we received an array of users in the form {id:..., name:..., age:... }.
// Create a function groupById(arr) that creates an object from it, with id as the key, and array items as values.
// function groupById(users) {
// return users.reduce((obj, user) => {
// obj[user.id] = user;
// return obj;
// }, {});
// }
let users = [
{id: 'john', name: "John Smith", age: 20},
{id: 'ann', name: "Ann Smith", age: 24},
{id: 'pete', name: "Pete Peterson", age: 31},
];
let usersById = groupById(users);
console.log(usersById);
/*
// after the call we should have:
usersById = {
john: {id: 'john', name: "John Smith", age: 20},
ann: {id: 'ann', name: "Ann Smith", age: 24},
pete: {id: 'pete', name: "Pete Peterson", age: 31},
}
*/
728x90

https://www.acmicpc.net/problem/2440

😢 단순 출력 문제

😊 row가 증가할 때마다 n-row만큼 줄어들도록 *을 출력하면 된다
row는 1개씩 증가하니
5를 입력받았을 경우
5-0, *****
5-1, ****
5-2, ***
5-3, **
5-4, *

#include <iostream>
using namespace std;
int main() {
ios::sync_with_stdio(false), cin.tie(nullptr);
int n;
cin >> n;
for (int row = 0; row < n; row++) {
for (int col = 0; col < n - row; col++) cout << '*';
cout << '\n';
}
}
view raw 2440.cpp hosted with ❤ by GitHub

+ Recent posts