tinycodinglm / cp2 /cp-0024.jsonl
winapiadmin's picture
Upload folder using huggingface_hub (part 15)
b27bfb3 verified
|
Raw History Blame Contribute Delete
3.88 kB
{"type": "session", "harness": "cp-practice-sim", "id": "cp-0024", "name": "Drifting Caesar Cipher", "mode": "chat", "topic": "String manipulation and parsing", "difficulty": "easy", "tags": ["strings", "cipher", "modular arithmetic"], "explanation_mode": "none", "tool_scenario": "none", "expected_recovery": "N/A - no fault injected.", "languages": ["rust", "typescript", "cpp"], "unexecuted_languages": [], "time_complexity": "O(n)", "space_complexity": "O(n)"}
{"type": "message", "message": {"role": "system", "content": "You are a competitive-programming assistant. Deliver correct, complete, runnable solutions that read standard input and write standard output. Reply with code only; no explanation. ", "timestamp": 1794086401700}}
{"type": "message", "message": {"role": "user", "content": "# Drifting Caesar Cipher\n\nTopic: String manipulation and parsing | Difficulty: easy\n\n## Problem\nEncrypt a text as follows. Number the letters of the text (ignoring every other character) starting from 0. The letter with number i is shifted forward in the alphabet by (k + i) mod 26 positions, wrapping from z to a, preserving whether it is upper or lower case. All non-letter characters stay unchanged. Print the encrypted text.\n\n## Input\nThe first line contains the integer k. The second line contains the text.\n\n## Output\nPrint the encrypted text on one line.\n\n## Constraints\n- 0 <= k <= 10^9\n- 1 <= text length <= 2*10^5\n- the text contains printable ASCII characters\n\n## Examples\n### Example 1\nInput:\n```\n1\nabc xyz\n```\nOutput:\n```\nbdf bdf\n```\nNote: Shifts are 1,2,3,4,5,6; the space is skipped when numbering letters.\n\n### Example 2\nInput:\n```\n0\nHello, World!\n```\nOutput:\n```\nHfnos, Buytm!\n```\n\nSolve this in Rust, TypeScript, C++17, one complete program per language. Code only, no explanation.", "timestamp": 1794086403537}}
{"type": "message", "message": {"role": "assistant", "content": "### Rust\n```rust\nuse std::io::*;\nfn main() {\n let mut s = String::new();\n stdin().read_to_string(&mut s).unwrap();\n let mut lines = s.split('\\n');\n let k: u64 = lines.next().unwrap().trim().parse().unwrap();\n let text = lines.next().unwrap_or(\"\").trim_end_matches('\\r');\n let mut out = String::new();\n let mut i: u64 = 0;\n for ch in text.chars() {\n if ch.is_ascii_alphabetic() {\n let base = if ch.is_ascii_lowercase() { b'a' } else { b'A' };\n let sh = ((k + i) % 26) as u8;\n out.push(((ch as u8 - base + sh) % 26 + base) as char);\n i += 1;\n } else {\n out.push(ch);\n }\n }\n println!(\"{}\", out);\n}\n```\n\n### TypeScript\n```typescript\ndeclare const require: any;\nconst lines: string[] = require('fs').readFileSync(0, 'utf8').split('\\n');\nconst k = parseInt(lines[0].trim());\nconst text = (lines[1] || '').replace(/\\r$/, '');\nlet out = '';\nlet i = 0;\nfor (const ch of text) {\n const c = ch.charCodeAt(0);\n const lower = c >= 97 && c <= 122;\n const upper = c >= 65 && c <= 90;\n if (lower || upper) {\n const base = lower ? 97 : 65;\n out += String.fromCharCode(((c - base + ((k + i) % 26)) % 26) + base);\n i++;\n } else {\n out += ch;\n }\n}\nconsole.log(out);\n```\n\n### C++17\n```cpp\n#include <bits/stdc++.h>\nusing namespace std;\nint main() {\n long long k;\n string text;\n cin >> k;\n getline(cin, text);\n getline(cin, text);\n if (!text.empty() && text.back() == '\\r') text.pop_back();\n long long i = 0;\n for (char &ch : text) {\n bool lo = ch >= 'a' && ch <= 'z', up = ch >= 'A' && ch <= 'Z';\n if (lo || up) {\n char base = lo ? 'a' : 'A';\n ch = (char)((ch - base + (k + i) % 26) % 26 + base);\n i++;\n }\n }\n printf(\"%s\\n\", text.c_str());\n}\n```", "timestamp": 1794086405511}}