cppAcademy
FROM LEARNING TO COMPETING

Real problems.
Your next challenge.

Explore the Group C Olympiad archive.
Choose a topic. Find a challenge. Build your solution.

213 tasks across the Municipal, Regional, and National rounds (2009–2026), plus 4 previously featured problems. 146 tasks have independently written English summaries, analyses, and C++17 solutions; the remaining entries link to Arena. Topic tags are from Arena or our reviewed explanations. Difficulty labels are learning estimates, not official ratings.
GROUP C2011 · MediumBit manipulation & decoding

System Administrators

National Olympiad — National round

Submission name: sysadmin.cpp

Problem summary

Four original character bytes are packed into a 32-bit word, first character most significant. Encoding rotates that word K bits right and prints its bytes as four decimal values separated by dots. Decode every encoded group and concatenate its four original characters.

Input

K, followed by dotted groups until EOF; there is no count.

Output

The decoded message on one line, preserving its spaces.

Constraints

0 ≤ K ≤ 31; at most 1,000,000 groups; each component is 0…255; original length is divisible by four.

Worked example

An independently prepared example for this explanation.

Input

0
67.79.68.69

Output

CODE

Solution analysis

  1. Pack the four encoded bytes in big-endian order.
  2. Rotate the unsigned 32-bit word left by K.
  3. Output its four bytes in the original order.

Why it works

The inverse of a right rotation is a left rotation by the same amount. Unpacking restores the original byte sequence.

Complexity: O(number of groups) time; O(1) auxiliary memory.

Watch out. Handle K=0 separately; shifting a 32-bit value by 32 is undefined.

Commented C++17 solution

An independently written complete program with standard headers.

#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<string>
#include<limits>
#include<numeric>
#include<set>
#include<map>
#include<tuple>
#include<cstdint>
#include<functional>
#include<cmath>
using namespace std;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int k;
    cin>>k;
    uint32_t a,b,c,d;
    char dot;
    while(cin>>a>>dot>>b>>dot>>c>>dot>>d){
        uint32_t x=(a<<24)|(b<<16)|(c<<8)|d;
        if(k){
            x=(x<<k)|(x>>(32-k)); // Invert the circular rotation.
        }
        for(int shift=24;shift>=0;shift-=8){
            cout.put(char((x>>shift)&255));
        }
    }
    cout<<'\n';
}

Source: Arena Olimpiici ↗