UIU Competitive Programmers contest – 02 Solution


A – QQ


// @BEGIN_OF_SOURCE_CODE

#include <cstdio>

using namespace std;

int main ()
{
    for (int firstNumber = 1; firstNumber <= 9; firstNumber++) {
        for (int secondNumber = 1; secondNumber <= 9; secondNumber++) {
            printf ("%dx%d=%d\n", firstNumber, secondNumber, firstNumber * secondNumber);
        }
    }

    return 0;
}

// @END_OF_SOURCE_CODE

B – Sorting Five Numbers


// @BEGIN_OF_SOURCE_CODE

#include <cstdio>
#include <algorithm>
#import <functional>

using namespace std;

int main ()
{
    int nums [5];

    for (int i = 0; i < 5; i++)
        scanf ("%d", &nums [i]);

    // descending order sort
    sort(nums, nums + 5, greater<int>());

    bool space = false;

    for (int i = 0; i < 5; i++) {
        if (space) printf (" ");
        space = true;
        printf ("%d", nums [i]);
    }

    printf ("\n");

    return 0;
}

// @END_OF_SOURCE_CODE

C – Digit Number


// @BEGIN_OF_SOURCE_CODE

#include <cstdio>

using namespace std;

int main ()
{
    int a, b;

    while (scanf ("%d %d", &a, &b) != EOF) {
        int sum = a + b;
        int ret = 0;

        while(sum) {
            sum /= 10;
            ret++;
        }

        printf("%d\n", ret);
    }

    return 0;
}

// @END_OF_SOURCE_CODE

D – GCD and LCM


// @BEGIN_OF_SOURCE_CODE

#include <iostream>

#define LL long long

using namespace std;

LL gcd(LL a, LL b)
{
    if (b == 0) return a;

    return gcd(b, a % b);
}

int main ()
{
    LL a, b;

    while(cin >> a >> b) {
        LL gcdVal = gcd(a, b);
        LL lcmVal = a * b / gcdVal;

        cout << gcdVal << " " << lcmVal << endl;
    }


    return 0;
}

// @END_OF_SOURCE_CODE

E – List of Top 3 Hills


// @BEGIN_OF_SOURCE_CODE

#include <cstdio>
#include <algorithm>

using namespace std;

int main ()
{
    int heights [10 + 5];

    for (int i = 0; i < 10; i++) {
        scanf ("%d", &heights[i]);
    }

    sort(heights, heights + 10);

    printf ("%d\n%d\n%d\n", heights [9], heights [8], heights [7]);

    return 0;
}

// @END_OF_SOURCE_CODE

UIU Competitive Programmers Contest – 01 Solution


A – A+B for Input-Output Practice (I)


// @BEGIN_OF_SOURCE_CODE

#include <iostream>

using namespace std;

int main ()
{
    int a;
    int b;

    while (scanf ("%d %d", &a, &b) != EOF) {
        printf ("%d\n", a + b);
    }

    return 0;
}

// @END_OF_SOURCE_CODE

B – A+B for Input-Output Practice (II)


// @BEGIN_OF_SOURCE_CODE

#include <iostream>

using namespace std;

int main ()
{
    int n;

    scanf ("%d", &n);

    int a;
    int b;

    while (n--) {
        scanf ("%d %d", &a, &b);
        printf ("%d\n", a + b);
    }

    return 0;
}

// @END_OF_SOURCE_CODE

C – A+B for Input-Output Practice (III)


// @BEGIN_OF_SOURCE_CODE

#include <iostream>

using namespace std;

int main ()
{
    int a;
    int b;

    while (true) {
        scanf ("%d %d", &a, &b);
        if (a == 0 && b == 0) break;
        printf ("%d\n", a + b);
    }

    return 0;
}

// @END_OF_SOURCE_CODE

D – A+B for Input-Output Practice (IV)


// @BEGIN_OF_SOURCE_CODE

#include <iostream>

using namespace std;

int main ()
{
    int n;

    while (true) {
        scanf ("%d", &n);

        if (n == 0) break;
        
        int num;
        int sum = 0;

        for ( int i = 0; i < n; i++ ) {
            scanf ("%d", &num);
            sum += num;
        }
        
        printf ("%d\n", sum);
    }



    return 0;
}

// @END_OF_SOURCE_CODE

E – A+B for Input-Output Practice (V)


// @BEGIN_OF_SOURCE_CODE

#include <iostream>

using namespace std;

int main ()
{
    int n;

    scanf ("%d", &n);

    while (n--) {
        
        int m;
        scanf ("%d", &m);
        
        int num;
        int sum = 0;

        for ( int i = 0; i < m; i++ ) {
            scanf ("%d", &num);
            sum += num;
        }

        printf ("%d\n", sum);
    }

    return 0;
}

// @END_OF_SOURCE_CODE

F – A+B for Input-Output Practice (VI)


// @BEGIN_OF_SOURCE_CODE

#include <iostream>

using namespace std;

int main ()
{
    int n;

    while (scanf ("%d", &n) != EOF) {

        int num;
        int sum = 0;

        for ( int i = 0; i < n; i++ ) {
            scanf ("%d", &num);
            sum += num;
        }

        printf ("%d\n", sum);
    }

    return 0;
}

// @END_OF_SOURCE_CODE

G – A+B for Input-Output Practice (VII)


// @BEGIN_OF_SOURCE_CODE

#include <iostream>

using namespace std;

int main ()
{
    int a;
    int b;

    while (scanf ("%d %d", &a, &b) != EOF) {

        printf ("%d\n\n", a + b);
    }

    return 0;
}

// @END_OF_SOURCE_CODE

H – A+B for Input-Output Practice (VIII)


// @BEGIN_OF_SOURCE_CODE

#include <iostream>

using namespace std;

int main ()
{
    int n;
    
    scanf ("%d", &n);
    
    bool blankLine = false;
    
    while (n--) {
        
        int m; 
        scanf ("%d", &m);
        
        int num;
        int sum = 0;
        
        for ( int i = 0; i < m; i++ ) {
            scanf ("%d", &num);
            sum += num;
        }
        
        if (blankLine) printf ("\n");
        
        blankLine = true;
        
        printf ("%d\n", sum);
    }

    return 0;
}

// @END_OF_SOURCE_CODE

I – Reverse Sequence


// @BEGIN_OF_SOURCE_CODE

#include <cstdio>
#include <cstring>

using namespace std;

int main ()
{
    char str [20 + 10];

    scanf ("%s", str);

    int length = strlen(str);

    for ( int i = length - 1; i >= 0; i-- )
        printf ("%c", str [i]);

    printf ("\n");

    return 0;
}

// @END_OF_SOURCE_CODE

J – Factorial


// @BEGIN_OF_SOURCE_CODE

#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;

int main ()
{
    int n;

    scanf("%d", &n);

    long long fact = 1;

    for ( int i = 1; i <= n; i++ )
        fact *= i;

    cout << fact << endl;

    return 0;
}

// @END_OF_SOURCE_CODE

K – Prime Number


// @BEGIN_OF_SOURCE_CODE

#include <iostream>
#include <cstdio>
#include <cmath>

using namespace std;

bool prime [999999 + 10];

bool isPrime(int n) {

    // all numbers less than 2 is not prime
    if (n < 2) return false;

    // 2 is only even prime
    if (n == 2) return true;

    // others even numbers are not prime
    if (n % 2 == 0) return false;

    int squareRoot = (int) sqrt(n);

    for ( int i = 3; i <= squareRoot; i += 2 ) {
        if (n % i == 0) return false;
    }

    return true;
}

void preCalculation()
{
    for ( int i = 0; i <= 999999; i++ ) {
        prime [i] = isPrime(i);
    }

}

int main ()
{
    preCalculation();

    int n;

    while (scanf ("%d", &n) != EOF) {

        int count = 0;

        for ( int i = 2; i <= n; i++ ) {
            if (prime [i]) count++;
        }

        printf ("%d\n", count);
    }

    return 0;
}

// @END_OF_SOURCE_CODE

UIU: Competitive Programming: Class – 03


Palindrome check


// @BEGIN_OF_SOURCE_CODE

#include <cstdio>
#include <cstring>
#import <algorithm>

using namespace std;

bool isPalindrome(char str [])
{
    int length = strlen (str);

    char copy [length];

    // making a copy of original string
    strcpy(copy, str);

    reverse(copy, copy + length);

    return strcmp(copy, str) == 0;
}

int main(int argc, const char * argv[])
{
    char input [100];

    scanf ("%s", input);

    if (isPalindrome(input)) {
        printf ("Palindrome\n");

    } else {
        printf ("Not Palindrome\n");
    }

    return 0;
}

// @END_OF_SOURCE_CODE

Prime factor


// @BEGIN_OF_SOURCE_CODE

#include <cstdio>
#import <cmath>

using namespace std;

bool isPrime(int n)
{
    if ( n < 2 ) return false;

    if ( n == 2 ) return true;

    if ( n % 2 == 0 ) return false;

    int squareRoot = (int) sqrt(n);

    for ( int i = 3; i <= squareRoot; i += 2 ) {
        if ( n % i == 0 ) return false;
    }

    return true;
}

int nextPrime(int n)
{
    while(!isPrime(++n));

    return n;
}

int main(int argc, const char * argv[])
{
    // 36 = 2 * 2 * 3 * 3;
    int input;

    scanf ("%d", &input);

    int primeNumber = nextPrime(0);

    while (input != 1) {
        while (input % primeNumber == 0) {
            printf ("%d\n", primeNumber);
            input /= primeNumber;
        }

        primeNumber = nextPrime(primeNumber);
    }

    return 0;
}

// @END_OF_SOURCE_CODE

GCD and LCM


// @BEGIN_OF_SOURCE_CODE

#include <cstdio>

using namespace std;

int gcd(int a, int b)
{
    if ( a == 0 ) return b;

    return gcd(b % a, a);
}

int lcm(int a, int b)
{
    return (a * b) / gcd(a, b);
}

int main(int argc, const char * argv[])
{
    printf ("%d\n", gcd(42, 36));

    printf ("%d\n", gcd(36, 42));

    printf ("%d\n", lcm(36, 42));

    return 0;
}

// @END_OF_SOURCE_CODE

Input from a file and Output in a file

1. Create a file named “in.txt” in same location of your source cpp file

2. Write two integer number in “in.txt” file

for example,
2 5

// @BEGIN_OF_SOURCE_CODE

#include <cstdio>

using namespace std;

int main(int argc, const char * argv[])
{
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);

    int a, b;

    scanf ("%d %d", &a, &b);

    printf ("%d\n", a + b);

    return 0;
}

// @END_OF_SOURCE_CODE

UIU: Learn C by Examples : Reverse


Reverse string naive approach


#include <cstdio>
#include <cstring>

using namespace std;

int main(int argc, const char * argv[])
{
    char mainString [50] = "Hello";

    printf ("Main String: %s\n", mainString);

    int lengthMainString = strlen(mainString);

    char reverseString [50];

    int reverseIndex = lengthMainString - 1;

    for ( int i = 0; i < lengthMainString; i++ ) {
        reverseString [reverseIndex] = mainString [i];
        reverseIndex--;
    }

    reverseString [lengthMainString] = '\0';

    printf ("Reverse String: %s\n", reverseString);

    return 0;
}


Main String: Hello
Reverse String: olleH

Reverse string (length / 2) approach


#include <cstdio>
#include <cstring>

using namespace std;

void swap (char *a, char *b)
{
    char temp = *b;
    *b = *a;
    *a = temp;
}

int main(int argc, const char * argv[])
{
    char mainString [50] = "Hello";

    printf ("Main String: %s\n", mainString);

    int lengthMainString = strlen(mainString);

    for ( int i = 0; i < lengthMainString / 2; i++ ) {
        swap(&mainString [i], &mainString [lengthMainString - 1 - i]);
    }

    printf ("Reverse String: %s\n", mainString);

    return 0;
}


Main String: Hello
Reverse String: olleH

Reverse string STL approach


#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

int main(int argc, const char * argv[])
{
    char mainString [50] = "Hello";

    printf ("Main String: %s\n", mainString);

    int lengthMainString = strlen(mainString);

    reverse(mainString, mainString + lengthMainString);

    printf ("Reverse String: %s\n", mainString);

    return 0;
}



Main String: Hello
Reverse String: olleH

Reverse number sprintf approach


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cstdlib>

using namespace std;

int main(int argc, const char * argv[])
{
    int n = 12345;

    char number [50];

    sprintf(number, "%d", n);

    reverse(number, number + strlen (number));

    printf ("Reverse Number: %s\n", number);

    // convert a string to integer
    int reverseNumber = atoi(number);

    printf ("Reverse Number: %d\n", reverseNumber);

    return 0;
}


Reverse Number: 54321
Reverse Number: 54321

Reverse number modulus approach


#include <cstdio>

using namespace std;

int reverseNumber(int n)
{
    int ret = 0;

    while ( n ) {
        ret = 10 * ret + n % 10;
        n /= 10;
    }

    return ret;
}

int main(int argc, const char * argv[])
{
    int n = 12345;

    printf ("Reverse Number: %d\n", reverseNumber(n));

    return 0;
}


Reverse Number: 54321

Trip To Thailand With Kaz Software


Launch from Bangladesh

Launch from BD

Suvarnabhumi Airport

Thailand Airport

Snacks at KFC

Snacks

Toilet for Men

Male Toilet

Toilet for Women

Female Toilet

Krabi Aonang Resort

Hotel room

Krabi Beach

IMG_0148

IMG_0153

IMG_0252

Railey Beach, Krabi

IMG_0284

IMG_0293

IMG_0298

IMG_0311

Out of Nowhere

IMG_0353

IMG_0369

Phi Phi Island

IMG_0375

IMG_0472

Out of Nowhere again

IMG_0474

IMG_0476

IMG_0511

Another Beach (forgot the name!)

IMG_0521

IMG_0525

IMG_0526

Again Another Beach (forgot the name! again!!)

IMG_0554

IMG_0560

IMG_0561

IMG_0562

IMG_0583

IMG_0589

IMG_0603

Bangladeshi Restaurant

IMG_0606

Street Food, Bangkok

IMG_0610

IMG_0617

Unicorn Express Hotel

IMG_0620

IMG_0621

IMG_0630

IMG_0631

IMG_0635

Way to Siam Paragon

IMG_0640

Siam Paragon (Shopping Mall)

IMG_0648

IMG_0655

IMG_0662

IMG_0663

IMG_0682

Buffet Breakfast Unicorn Express Hotel

IMG_0692

IMG_0697

IMG_0701

IMG_0704

Dragon Fruit

IMG_0707

Prayer place, Siam Center

IMG_0721

MDK Center, Bankok (Shopping mall)

IMG_0727

Bangkok Road

IMG_0728

Important consideration before accepting a Development job offer


You should consider the following acceptance criteria before making a decision to take a Software development job offer.

If the company uses Source Control Management.

If the company follows Software Development cycle

If the company uses Continuous integration system

If the company has Senior/Principal Software Engineer/Architect

If you need to work in a team or alone

If the company has QA (Quality Assurance) team

If you need to overwork.

Courtesy: Shah Ali Newaz (Topu) vai