Beginning with solving problems: Super Easy Problems

Super Easy:

The books give a reference to 15 super easy problems to get started. Here is the list of them:

Super Easy Problems in the UVa Online Judge (solvable in under 7 minutes)
  1. UVa 00272 - TEX Quotes (replace all double quotes to TEX() style quotes)
  2. UVa 01124 - Celebrity Jeopardy (LA 2681, just echo/re-print the input again)
  3. UVa 10550 - Combination Lock (simple, do as asked)
  4. UVa 11044 - Searching for Nessy (one-liner code/formula exists)
  5. UVa 11172 - Relational Operators * (ad hoc, very easy, one-liner)
  6. UVa 11364 - Parking (linear scan to get l & r, answer = 2 ∗ (r − l))
  7. UVa 11498 - Division of Nlogonia * (just use if-else statements)
  8. UVa 11547 - Automatic Answer (a one-liner O(1) solution exists)
  9. UVa 11727 - Cost-Cutting * (sort the 3 numbers and get the median)
  10. UVa 12250 - Language Detection (LA 4995, KualaLumpur10, if-else check)
  11. UVa 12279 - Emoogle Balance (simple linear scan)
  12. UVa 12289 - One-Two-Three (just use if-else statements)
  13. UVa 12372 - Packing for Holiday (just check if all L, W, H ≤ 20)
  14. UVa 12403 - Save Setu (straightforward)
  15. UVa 12577 - Hajj-e-Akbar (straightforward)

Here are the solutions to the first ten of these, I request solve them on your own before looking at the solutions.


Since these are just easy problems, I am not writing any hints.

UVa 00272: TEX quotes

#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
using namespace std;
int main(int argc, char const *argv[]) {
string s;
int c=0;
while (getline(cin, s)) {
int len = s.length();
for (size_t i = 0; i < len; i++) {
if(s[i]=='"'){
if(c%2==0)
printf("``");
else
printf("''");
c++;
}else{
printf("%c", s[i]);
}
}4
printf("\n");
}
return 0;
}

UVa 01124 : Celebrity Jeopardy

#include <iostream>
using namespace std;
int main(int argc, char const *argv[]) {
string s;
while (getline(cin, s), s!="\n") {
if(s.length()==0)
break;
cout<<s<<endl;
}
return 0;
}

UVa 10550: Combination Lock

#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
int initial, pos1, pos2, pos3;
cin>>initial>>pos1>>pos2>>pos3;
while (initial||pos1||pos2||pos3) {
int out = 1080;
if(initial>pos1)
out += ((initial-pos1)*9);
else
out += 360 - (pos1-initial)*9;
if(pos2>pos1)
out += (pos2-pos1)*9;
else
out += 360 - ((pos1-pos2)*9);
if(pos3<pos2)
out += (pos2-pos3)*9;
else
out += 360 - ((pos3-pos2)*9);
cout<<out<<endl;
cin>>initial>>pos1>>pos2>>pos3;
}
return 0;
}

UVa 11044: Searching for Nessy

#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
int t;
scanf("%d", &t);
while (t--) {
float a, b;
// cin>>a>>b;
scanf("%f %f", &a, &b);
float temp = (a-2)/3;
float temp2 = (b-2)/3;
int result = ceil(temp)*ceil(temp2);
printf("%d\n", result);
}
return 0;
}

UVa 11172: Relational Operators

int main(int argc, char const *argv[]) {
int t;
scanf("%d", &t);
while (t--) {
lli a, b;
scanf("%lld %lld", &a, &b);
if(a<b)
printf("<\n4");
if(a>b)
printf(">\n");
if(a==b)
printf("=\n");
}
return 0;
}
UVa 11364: Parking
int main(int argc, char const *argv[]) {
int t;
scanf("%d\n", &t);
while (t--) {
int n;
scanf("%d\n", &n);
int arr[n];
for (size_t i = 0; i < n; i++) {
scanf("%d", &arr[i]);
}
sort(arr, arr+n);
int result = 2*(arr[n-1]-arr[0]);
printf("%d\n", result);
}
return 0;
}

Uva 11498: Division of Nlogonia
#include <stdio.h>
int main() {
int n, x, y, a, b;
while(scanf("%d", &n) == 1 && n) {
scanf("%d %d", &x, &y);
while(n--) {
scanf("%d %d", &a, &b);
if(a == x || b == y)
puts("divisa");
else if(a > x && b > y)
puts("NE");
else if(a < x && b > y)
puts("NO");
else if(a < x && b < y)
puts("SO");
else
puts("SE");
}
}
return 0;
}


Uva 11547: Automatic Answer
int main(int argc, char const *argv[]) {
int t;
scanf("%d\n", &t);
while (t--) {
int n;
scanf("%d\n", &n);
int temp = (((n*63)+7492)*5)-498;
temp = temp/10;
temp = abs(temp%10);
printf("%d\n", temp);
}
return 0;
}


Uva 11727: Cost Cutting
int main(int argc, char const *argv[]) {
int t;
scanf("%d\n", &t);
for(int i=0;i<t;i++) {
int arr[3];
scanf("%d %d %d", &arr[0], &arr[1], &arr[2]);
sort(arr, arr+3);
printf("Case %d: %d\n", i+1, arr[1]);
}
return 0;
}


Uva 12250: Language Detection
int main(int argc, char const *argv[]) {
string s;
int i=1;
while(cin>>s, s!="#"){
if(s=="HELLO"){
printf("Case %d: ENGLISH\n", i);
}else if(s=="HOLA"){
printf("Case %d: SPANISH\n", i);
}else if(s=="HALLO"){
printf("Case %d: GERMAN\n", i);
}else if(s=="BONJOUR"){
printf("Case %d: FRENCH\n", i);
}else if(s=="CIAO"){
printf("Case %d: ITALIAN\n", i);
}else if(s=="ZDRAVSTVUJTE"){
printf("Case %d: RUSSIAN\n", i);
}else{
printf("Case %d: UNKNOWN\n", i);
}
i++;
}
return 0;
}



No comments:

Post a Comment

Installing albert on ubuntu 19.04

Installing Albert on Ubuntu 19.04... Albert is not still released for ubuntu 19.04. But still, you can install it using the following ...