0% found this document useful (0 votes)
3 views

WeCode Week3

Uploaded by

Đức Nguyễn
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

WeCode Week3

Uploaded by

Đức Nguyễn
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

1)

)#include <cstdio>
int main() {
int a, b;
scanf("%d\n%d", &a, &b);
if (a == b) {
printf("1");
}
else {
printf("0");
}
return 0;
}

2)
#include <iostream>
#include <iomanip>

int main() {
long a, b;
std::cin >> a >> b;

if (b == 0) {
std::cout << "Congrats! Miss Phong Bat is here!";
return 0;
}
if (a < b) {
std::cout << "Khiem ton, dang tuyen duong!";
}
if (a > b) {
std::cout << "Phong bat tien ung ho ";
if (a % b != 0) {
std::cout << std::setprecision(2) << std::fixed << (double) a / b << " lan!";
}
else {
std::cout << a / b << " lan!";
}
}
if (a == b) {
std::cout << "Dang tuyen duong!";
}

return 0;
}

3)
#include <iostream>

int main() {
double a;
double b;
double c;
std::cin >> a >> b >> c;

if (a > b) std::swap(a, b);


if (a > c) std::swap(a, c);
if (b > c) std::swap(b, c);
std::cout << a << " " << b << " " << c;

return 0;
}
4)
#include <iostream>
#include <math.h>

int main() {
long p, s;

std::cin >> s >> p;

double _delta = (p / 2.0) * (p / 2.0) - 4.0 * s;

if ((p == 0) && (s == 0)) {


std::cout << "0 0";
return 0;
}

if ((_delta < 0.0) || (p <= 0) ||(s <= 0)) {


std::cout << "NA";
return 0;
}

double x_1 = ((p / 2.0) + sqrt(_delta)) / 2.0;


double x_2 = ((p / 2.0) - sqrt(_delta)) / 2.0;

std::cout << ((x_1 > x_2)? x_1: x_2) << " " << ((x_1 < x_2)? x_1: x_2);
return 0;
}
5)
#include <iostream>

int main() {
long v1, v2, x1, x2;

std::cin >> x1 >> v1 >> x2 >> v2;

if (v1 == v2) {
if (x1 == x2) {
std::cout << "YES\n";
}
else {
std::cout << "NO\n";
}
return 0;
}
else {
if ((x2 - x1) % (v1 - v2) == 0 && (x2 - x1) / (v1 - v2) > 0) {
std::cout << "YES\n";
}
else {
std::cout << "NO\n";
}
}
return 0;
}
6)
#include <iostream>

int main() {
long n, k, p, q;
std::cin >> n >> k >> p >> q;

/* Xác định nếu A nằm ở đợt đề đầu tiên hay không*/


bool a_is_first_series = false;
long a_index = 2 * (p - 1) + (q - 1);
// std::cout << "a_index = " << a_index << "\n";
if (a_index / k == 0) {
a_is_first_series = true;
}
// std::cout << "a_is_first_series = " << a_is_first_series << "\n";

/* Nếu a nằm ở đợt đề đầu tiên thì b sẽ nằm ở đợt đề 2. Còn nếu a nằm ở
đợt đề x thì b sẽ nằm ở đợt đề x + 1 */
long b_index;
if (a_is_first_series) {
b_index = k + (a_index % k);
}
else {
b_index = ((a_index / k) - 1) * k + (a_index % k);
}
// std::cout << "b_index = " << b_index << "\n";

if ((b_index < 0) || (b_index > n - 1)) {


std::cout << "-1";
return 0;
}
std::cout << ((b_index / 2) + 1) << " " << ((b_index % 2) + 1);
return 0;
}
7)
#include <iostream>
#include <cmath>
using namespace std;

int main() {
char c1, c2;
int x;
cin >> c1 >> c2 >> x;
cout << "Ma ASCII cua ky tu '" << c1 << "', '" << c2 << "' lan luot la "
<< int(c1) << " va " << int(c2) << endl;

int distance = abs(c1 - c2);


cout << "Khoang cach giua hai ky tu '" << c1 << ", '" << c2 << "' la " <<
distance << endl;

cout << "Dang viet hoa cua ky tu '" << c1 << "' la '" << char(c1 - 32)
<< "'" << endl;
cout << x << " la ma ASCII cua ky tu '" << char(x) << "'" << endl;

return 0;
}

You might also like