Analyzing CSP-J Preliminary Round Exam Questions from 2017
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;
}