Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

Analyzing CSP-J Preliminary Round Exam Questions from 2017

Tech May 3 26

Multiple Choice Questions

Question 1

In 8-bit two's complement representation, the binary number 10101011 corresponds to which decimal value?

Options: A. 43 B. -85 C. -43 D. -84

Answer: B

Explanation: The most significnat bit indicates negativity. Covnerting from two's complement yields -85.

Question 2

What is the fundamental unit of computer data storage?

Options: A. bit B. Byte C. GB D. KB

Answer: B

Question 3

Which protocol is NOT related to email?

Options: A. POP3 B. SMTP C. WTO D. IMAP

Answer: C

Problem Solving

Question 21

A person starts at (0,0) facing the positive x-axis. Each round they move forward (increasing distance) and turn right. After 2017 rounds, what are their coordinates?

Answer: (1009, 1008)

Code Analysis

Question 23

#include <iostream>
using namespace std;

int main() {
    int freq[256] = {0};
    string input;
    cin >> input;
    
    for(char c : input) freq[c]++;
    for(char c : input) {
        if(freq[c] == 1) {
            cout << c << endl;
            return 0;
        }
    }
    cout << "no" << endl;
    return 0;
}

Input: "xyzxyw"

Output: z

Code Completion

Question 27-31 (Fast Exponentiation)

int fastPow(int x, int p, int m) {
    int result = 1;
    while(p > 0) {
        if(p % 2 == 1)
            result = (result * x) % m;
        p /= 2;
        x = (x * x) % m;
    }
    return result;
}

Question 32-36 (Rope Cutting)

int maxRopeLength(int ropes[], int n, int m) {
    int total = 0;
    for(int i=0; i<n; i++) total += ropes[i];
    
    if(total < m) return -1; // Failed
    
    int left = 1, right = 1000000;
    while(left < right) {
        int mid = (left + right + 1) / 2;
        int count = 0;
        for(int i=0; i<n; i++)
            count += ropes[i] / mid;
            
        if(count < m) right = mid - 1;
        else left = mid;
    }
    return left;
}

Related Articles

Comprehensive Guide to SSTI Explained with Payload Bypass Techniques

Introduction Server-Side Template Injection (SSTI) is a vulnerability in web applications where user input is improper handled within the template engine and executed on the server. This exploit can r...

Implement Image Upload Functionality for Django Integrated TinyMCE Editor

Django’s Admin panel is highly user-friendly, and pairing it with TinyMCE, an effective rich text editor, simplifies content management significantly. Combining the two is particular useful for bloggi...

SBUS Signal Analysis and Communication Implementation Using STM32 with Fus Remote Controller

Overview In a recent project, I utilized the SBUS protocol with the Fus remote controller to control a vehicle's basic operations, including movement, lights, and mode switching. This article is aimed...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.