CP Week 1

 

Day 1 – Basics: Input, Output, If-Else, Loops

📘 Focus Topic: Syntax, loops, if-else

  1. 71A – Way Too Long Words

#include <stdio.h>
#include <string.h>

int main() {
    int n;
    scanf("%d", &n);  // Read number of test cases

    for (int i = 0; i < n; i++) {
        char str[101];  // Word length can be up to 100 + 1 for null terminator
        scanf("%s", str);

        int len = strlen(str);

        if (len > 10) {
            printf("%c%d%c\n", str[0], len - 2, str[len - 1]);
        } else {
            printf("%s\n", str);
        }
    }

    return 0;
}

Here i havenot used getchar or fgets, the create confusion in cf. then, [101] cause
there is also null '\0' that is space, scanf will not scan space, but it will consume
a storage, so 101 is a must.. it will not affect other code.
if length>10 is a guess, so try hard to guess!

  1. 4A – Watermelon

easy
  1. 231A – Team

easy
  1. 1A – Theatre Square

here we should use long long, long double (%Lf) often. Int a/ int b= int value; if we want a float then (float)a/ b; it should be. Remember;

  1. 112A – Petya and Strings

  2. 282A – Bit++

  3. 50A – Domino Piling


Day 2 – Basic Math & Brute Force

📘 Focus Topic: Modulo, math, loops

  1. 617A – Elephant

  2. 158A – Next Round

  3. 546A – Soldier and Bananas

  4. 734A – Anton and Danik

  5. 791A – Bear and Big Brother

  6. 1328A – Divisibility Problem

  7. 1353B – Two Arrays And Swaps


Day 3 – Arrays: Traversal & Counting

📘 Focus Topic: Array operations, min/max

  1. 318A – Even Odds

  2. 69A – Young Physicist

  3. 734B – Anton and Digits

  4. 236A – Boy or Girl

  5. 339A – Helpful Maths

  6. 59A – Word

  7. 110A – Nearly Lucky Number

Completed!

Day 4 – Strings: Manipulation & Counting

📘 Focus Topic: Strings, case conversion, frequency

  1. 281A – Word Capitalization

  2. 41A – Translation

  3. 116A – Tram

  4. 785A – Anton and Polyhedrons

  5. 977A – Wrong Subtraction

  6. 1335A – Candies and Two Sisters

  7. 263A – Beautiful Matrix

Completed

Task How to solve
Is string a palindrome? Compare front and back chars using 2-pointer
Anagram check? Compare character frequency arrays
Count vowels/digits/specials `if (ch == 'a'
Case-insensitive comparison Convert both strings to same case first
Remove duplicates Use boolean array or frequency array

Concepts:
1.  frequency count in string:


int freq[26] = {0};  // for 'a' to 'z'

for (int i = 0; str[i]; i++) {
    if (str[i] >= 'a' && str[i] <= 'z') {
        freq[str[i] - 'a']++;
    }
}
angram check:
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

int asc(const void *a, const void *b)
{  return(*(int*)a-*(int*)b);

}


int main()


{ //silent listen
    char str1[8]="teacher";
    char str2[8]="cheater";

    int ascii1[100]; int k=0;
    for(int i=0; str1[i]!='\0';i++)
    {
        ascii1[k++]=(int)str1[i];
    }
   


 int ascii2[100]; int l=0;
    for(int i=0; str2[i]!='\0';i++)
    {
        ascii2[l++]=(int)str2[i];
    }
   
qsort(ascii1, k, sizeof(int), asc);
qsort(ascii2, l, sizeof(int), asc);

for(int i=0; i<k; i++)
{
    str1[i]=(char)ascii1[i];
}

for(int i=0; i<l; i++)
{
    str2[i]=(char)ascii2[i];
}

int result= strcmp(str1, str2);

printf("%d", result);

}

Day 5 – Sorting & Greedy Basics


🔍 Core Basics of Sorting Problems

1. ✅ Sort Numbers

Concept: Just sort numbers in ascending or descending order.

Skills: Use built-in sorting (qsort() in C) or manually sort.

📌 Example:

Input: 3 1 2 → Output: 1 2 3

🧪 Practice:


2. 🧠 Sort Strings

Concept: Sort strings alphabetically or by length.

📌 Example:

Input: bat, apple, car → After sort: apple bat car

🧪 Practice:


3. 📦 Sort with Original Index

Concept: Keep track of original position after sorting.

Technique: Use a struct or two arrays — one for value, one for original index.

🧪 Practice:


4. 🎯 Sort Then Greedy Selection

Concept: After sorting, make the best decision step-by-step.

📌 Example:

Pick smallest tasks first, or minimize cost.

🧪 Practice:


5. 📊 Sort + Frequency

Concept: Sort array and count how many times each number appears.

📌 Example:

Check if any number occurs more than once after sorting.

🧪 Practice:


6. 🔁 Two Pointers after Sort

Concept: After sorting, use two pointers from left and right to pair elements.

🧪 Practice:


✅ Daily Practice Plan (Beginner Sorting)

Try to solve 2 problems/day for the next few days:

Day 1:

Day 2:

Day 3:


📘 Focus Topic: Sorting for simplification

  1. 758A – Holiday Of Equality

  2. 144A – Arrival of the General

  3. 339B – Xenia and Ringroad

  4. 977B – Two-gram

  5. 266A – Stones on the Table

  6. [281A – Word Capitalization](repeat for review)

  7. [112A – Petya and Strings](repeat for mastery)


Day 6 – Review + Missed Problems

📘 Focus: Re-solve or finish any from earlier days

  • Pick 4 problems you failed or skipped.

  • Solve 3 new problems in your comfort range:

    • [339A – Helpful Maths](again for sorting)

    • [546A – Soldier and Bananas](easy math)

    • [1A – Theatre Square](geometry basics)


Day 7 – Simulated Contest Day

📘 Focus: Build contest skill under pressure

Solve these 7 problems in one sitting (90–120 mins):

  1. 71A – Way Too Long Words

  2. [158A – Next Round](math + condition)

  3. 231A – Team

  4. [282A – Bit++](easy loop)

  5. [69A – Young Physicist](array + logic)

  6. 339A – Helpful Maths

  7. [236A – Boy or Girl](string frequency)









LAST TASK:
??????????????????????????????????????????????????????????????
 Gellyfish and Baby's Breath

Comments

Popular posts from this blog

Phy 129 - WM, CT-03

Online 3 CSE 102; Array Resources.