diff --git a/challenges/ppc/online_judge/attachments/API.md b/challenges/ppc/online_judge/attachments/API.md new file mode 100644 index 0000000..043655d --- /dev/null +++ b/challenges/ppc/online_judge/attachments/API.md @@ -0,0 +1,100 @@ +# [PPC] 更适合破晓宝宝的 OJ API 文档 + +程序只有两个 API ,URL 路径都是 `/jobs`。 + +GET 请求返回全部已提交的任务,返回它们的状态和结果: + +```json +[ + { + "id": 0, + "created_time": "2023-10-16T18:34:16.287Z", + "updated_time": "2023-10-16T18:34:16.287Z", + "submission": { + "source_code": "#include \nint main() {\nprintf(\"Hello World!\");\nreturn 0;}", + "language": "C", + "problem_id": 0 + }, + "state": "Finished", + "result": "Accepted", + "cases": [ + { + "result": "Compilation Success", + "time": 0, + "memory": 0 + }, + { + "result": "Accepted", + "time": 0, + "memory": 0 + } + ], + "flag": "flag{" + }, + { + "id": 1, + "created_time": "2023-10-16T19:41:05.106Z", + "updated_time": "2023-10-16T19:41:05.106Z", + "submission": { + "source_code": "#include \nint main() {\nprintf(\"Hello World!\");\nreturn }", + "language": "C", + "problem_id": 0 + }, + "state": "Finished", + "result": "Compilation Error", + "cases": [ + { + "result": "Compilation Error", + "time": 0, + "memory": 0 + } + ], + "flag": "" + } +] +``` + +--- + +POST 请求提交 语言类型、题目 ID 、代码内容 ,返回此次评测结果: + +REQUEST: + +```json +{ + "language": "C", + "problem_id": 0, + "source_code": "#include \nint main() {\nprintf(\"Hello World!\");\nreturn 0;}", +} +``` + +RESPONSE: + +```json +{ + "id": 3, + "created_time": "2023-10-16T19:39:33.541Z", + "updated_time": "2023-10-16T19:39:33.541Z", + "submission": { + "source_code": "#include \nint main() {\nprintf(\"Hello World!\");\nreturn 0;}", + "language": "C", + "problem_id": 0 + }, + "state": "Finished", + "result": "Accepted", + "cases": [ + { + "result": "Compilation Success", + "time": 0, + "memory": 0 + }, + { + "result": "Accepted", + "time": 0, + "memory": 0 + } + ], + "flag": "flag{" +} +``` + diff --git a/challenges/ppc/online_judge/attachments/PROBLEMS.md b/challenges/ppc/online_judge/attachments/PROBLEMS.md new file mode 100644 index 0000000..c17b2f5 --- /dev/null +++ b/challenges/ppc/online_judge/attachments/PROBLEMS.md @@ -0,0 +1,110 @@ +# [PPC] 更适合破晓宝宝的 OJ 题单 + +每个题目名前的方括号中是题目 ID,如 `[0] 输出 Hello World!`,就代表着这题的 `problem_id` 为 `0`,在提交数据时使用以下 JSON : + +```json +{ + "language": "C", + "problem_id": 0, + "source_code": "#include \nint main() {\nprintf(\"Hello World!\");\nreturn 0;}", +} +``` + +**注意输出不要携带换行符,大小写敏感**。 + +## [0] 输出 Hello World! + +程序不接受任何输入,只输出 `Hello World!`。 + +**示例:** + +``` +输入:121 +输出:Hello World! +``` + +## [1] 回文数 + +给你一个整数,如果它是一个回文整数,返回 `true` ;否则,返回 `false` 。 + +回文数是指正序(从左向右)和倒序(从右向左)读都是一样的整数。 + +- 例如,`121` 是回文,而 `123` 不是。 + +**示例 1:** + +``` +输入:121 +输出:true +``` + +**示例 2:** + +``` +输入:-121 +输出:false +解释:从左向右读, 为 -121 。 从右向左读, 为 121- 。因此它不是一个回文数。 +``` + +**示例 3:** + +``` +输入:10 +输出:false +解释:从右向左读, 为 01 。因此它不是一个回文数。 +``` + +## [2] 转换成小写字母 + +给你一个字符串 `s` ,将该字符串中的大写字母转换成相同的小写字母,返回新的字符串。 + +**示例 1:** + +``` +输入:Hello +输出:hello +``` + +**示例 2:** + +``` +输入:here +输出:here +``` + +**示例 3:** + +``` +输入:LOVELY +输出:lovely +``` + +## [3] 倍数求和 + +给你一个正整数 `n` ,请你计算在 `[1,n]` 范围内能被 `3`、`5`、`7` 整除的所有整数之和。 + +返回一个整数,用于表示给定范围内所有满足约束条件的数字之和。 + +**示例 1:** + +``` +输入:7 +输出:21 +解释:在 [1, 7] 范围内能被 3、5、7 整除的所有整数分别是 3、5、6、7 。数字之和为 21 。 +``` + +**示例 2:** + +``` +输入:10 +输出:40 +解释:在 [1, 10] 范围内能被 3、5、7 整除的所有整数分别是 3、5、6、7、9、10 。数字之和为 40 。 +``` + +**示例 3:** + +``` +输入:9 +输出:30 +解释:在 [1, 9] 范围内能被 3、5、7 整除的所有整数分别是 3、5、6、7、9 。数字之和为 30 。 +``` diff --git a/challenges/ppc/online_judge/attachments/README.md b/challenges/ppc/online_judge/attachments/README.md new file mode 100644 index 0000000..7d268b8 --- /dev/null +++ b/challenges/ppc/online_judge/attachments/README.md @@ -0,0 +1,49 @@ +# [PPC] 更适合破晓宝宝的 OJ 使用指南 + +OJ 即 OnlineJudge,在线评测系统,用于自动评判编程代码的准确性和效率。 + +**你的程序要求实现接收特定的内容,并输出对应的正确内容**。 + +**你提交的代码,会在系统中编译后,根据提交的对应题目进行测试**。 + +**每道题都有一个或多个测试用例,用于判断你给出的程序的正确性**。 + +测试用例是的一组文件,分别对应着**程序输入**和**程序该有的输出**。当测试失败时,返回结果中可以看到是哪个测试用例因为什么失败,如答案错误。(不会有测试用例的具体内容) + +允许且推荐使用 ChatGPT 以及搜索引擎等工具,因为平台根本没法不允许,也没必要。 + +当然自己写的代码是最酷的。 + +不过,想想这题还能怎么做?这可是 CTF。 + +## FLAG 从哪来 ? + +每完成一道题目,会从服务器根目录的 `/flag`文件中返回一部分 FLAG。 + +每道题的 FLAG 片段都是固定的。 + +做题顺序不限制,但 FLAG 片段是有序的。 + +比如第一题,返回的就是 FLAG 第一个片段,第二题就是第二个片段,共四题,组合起来就是完整 FLAG 。 + +## 怎么做题 ? + +系统没有前端页面,只有一个 Web API ,你可以参照 [API 文档](API.md) 中的规范,使用任何可以发送 HTTP 包的工具来调用。 + +但由于在 JSON 中手写代码会遇到字符转义的痛苦事情,建议自写脚本或使用题目附件中提供的 `judge.py` 。 + +你需要修改 `judge.py` 中 `localhost` 为你的容器 IP。 + +修改 `judge.py` 中 `12345` 为你的容器端口。 + +并根据题目 ID 修改 `judge.py` 中 `problem_id` 为对应题目 ID。 + +修改 `test.c` 内容为你要提交的代码。 + +然后运行 `python judge.py`。 + +`judge.py` 会返回提交过所有任务的结果,而不是只有本次结果,以 JSON 格式显示。 + +## 语言 + +语言有两者可选 `C`、`CPP`,需要在 `judge.py` 修改 `language` 为 `"C"` 或 `"CPP"` diff --git a/challenges/ppc/online_judge/build/config.json b/challenges/ppc/online_judge/build/config.json index 716d083..873c0b7 100644 --- a/challenges/ppc/online_judge/build/config.json +++ b/challenges/ppc/online_judge/build/config.json @@ -18,11 +18,35 @@ }, { "id": 1, - "name": "hello_world", + "name": "palindrome_number", "cases": [ { - "input_file": "data/hello_world/1.in", - "answer_file": "data/hello_world/1.ans", + "input_file": "data/palindrome_number/1.in", + "answer_file": "data/palindrome_number/1.ans", + "time_limit": 2000000, + "memory_limit": 1048576 + }, + { + "input_file": "data/palindrome_number/2.in", + "answer_file": "data/palindrome_number/2.ans", + "time_limit": 2000000, + "memory_limit": 1048576 + }, + { + "input_file": "data/palindrome_number/3.in", + "answer_file": "data/palindrome_number/3.ans", + "time_limit": 2000000, + "memory_limit": 1048576 + }, + { + "input_file": "data/palindrome_number/4.in", + "answer_file": "data/palindrome_number/4.ans", + "time_limit": 2000000, + "memory_limit": 1048576 + }, + { + "input_file": "data/palindrome_number/5.in", + "answer_file": "data/palindrome_number/5.ans", "time_limit": 2000000, "memory_limit": 1048576 } @@ -30,11 +54,71 @@ }, { "id": 2, - "name": "hello_world", + "name": "to_lower_case", "cases": [ { - "input_file": "data/hello_world/1.in", - "answer_file": "data/hello_world/1.ans", + "input_file": "data/to_lower_case/1.in", + "answer_file": "data/to_lower_case/1.ans", + "time_limit": 2000000, + "memory_limit": 1048576 + }, + { + "input_file": "data/to_lower_case/2.in", + "answer_file": "data/to_lower_case/2.ans", + "time_limit": 2000000, + "memory_limit": 1048576 + }, + { + "input_file": "data/to_lower_case/3.in", + "answer_file": "data/to_lower_case/3.ans", + "time_limit": 2000000, + "memory_limit": 1048576 + }, + { + "input_file": "data/to_lower_case/4.in", + "answer_file": "data/to_lower_case/4.ans", + "time_limit": 2000000, + "memory_limit": 1048576 + }, + { + "input_file": "data/to_lower_case/5.in", + "answer_file": "data/to_lower_case/5.ans", + "time_limit": 2000000, + "memory_limit": 1048576 + } + ] + }, + { + "id": 3, + "name": "sum_multiples", + "cases": [ + { + "input_file": "data/sum_multiples/1.in", + "answer_file": "data/sum_multiples/1.ans", + "time_limit": 2000000, + "memory_limit": 1048576 + }, + { + "input_file": "data/sum_multiples/2.in", + "answer_file": "data/sum_multiples/2.ans", + "time_limit": 2000000, + "memory_limit": 1048576 + }, + { + "input_file": "data/sum_multiples/3.in", + "answer_file": "data/sum_multiples/3.ans", + "time_limit": 2000000, + "memory_limit": 1048576 + }, + { + "input_file": "data/sum_multiples/4.in", + "answer_file": "data/sum_multiples/4.ans", + "time_limit": 2000000, + "memory_limit": 1048576 + }, + { + "input_file": "data/sum_multiples/5.in", + "answer_file": "data/sum_multiples/5.ans", "time_limit": 2000000, "memory_limit": 1048576 } diff --git a/challenges/ppc/online_judge/build/data/palindrome_number/1.ans b/challenges/ppc/online_judge/build/data/palindrome_number/1.ans new file mode 100644 index 0000000..f32a580 --- /dev/null +++ b/challenges/ppc/online_judge/build/data/palindrome_number/1.ans @@ -0,0 +1 @@ +true \ No newline at end of file diff --git a/challenges/ppc/online_judge/build/data/palindrome_number/1.in b/challenges/ppc/online_judge/build/data/palindrome_number/1.in new file mode 100644 index 0000000..5a396e2 --- /dev/null +++ b/challenges/ppc/online_judge/build/data/palindrome_number/1.in @@ -0,0 +1 @@ +121 \ No newline at end of file diff --git a/challenges/ppc/online_judge/build/data/palindrome_number/2.ans b/challenges/ppc/online_judge/build/data/palindrome_number/2.ans new file mode 100644 index 0000000..02e4a84 --- /dev/null +++ b/challenges/ppc/online_judge/build/data/palindrome_number/2.ans @@ -0,0 +1 @@ +false \ No newline at end of file diff --git a/challenges/ppc/online_judge/build/data/palindrome_number/2.in b/challenges/ppc/online_judge/build/data/palindrome_number/2.in new file mode 100644 index 0000000..0a77e7b --- /dev/null +++ b/challenges/ppc/online_judge/build/data/palindrome_number/2.in @@ -0,0 +1 @@ +-121 \ No newline at end of file diff --git a/challenges/ppc/online_judge/build/data/palindrome_number/3.ans b/challenges/ppc/online_judge/build/data/palindrome_number/3.ans new file mode 100644 index 0000000..02e4a84 --- /dev/null +++ b/challenges/ppc/online_judge/build/data/palindrome_number/3.ans @@ -0,0 +1 @@ +false \ No newline at end of file diff --git a/challenges/ppc/online_judge/build/data/palindrome_number/3.in b/challenges/ppc/online_judge/build/data/palindrome_number/3.in new file mode 100644 index 0000000..9a03714 --- /dev/null +++ b/challenges/ppc/online_judge/build/data/palindrome_number/3.in @@ -0,0 +1 @@ +10 \ No newline at end of file diff --git a/challenges/ppc/online_judge/build/data/palindrome_number/4.ans b/challenges/ppc/online_judge/build/data/palindrome_number/4.ans new file mode 100644 index 0000000..f32a580 --- /dev/null +++ b/challenges/ppc/online_judge/build/data/palindrome_number/4.ans @@ -0,0 +1 @@ +true \ No newline at end of file diff --git a/challenges/ppc/online_judge/build/data/palindrome_number/4.in b/challenges/ppc/online_judge/build/data/palindrome_number/4.in new file mode 100644 index 0000000..bd7a502 --- /dev/null +++ b/challenges/ppc/online_judge/build/data/palindrome_number/4.in @@ -0,0 +1 @@ +1234554321 \ No newline at end of file diff --git a/challenges/ppc/online_judge/build/data/palindrome_number/5.ans b/challenges/ppc/online_judge/build/data/palindrome_number/5.ans new file mode 100644 index 0000000..f32a580 --- /dev/null +++ b/challenges/ppc/online_judge/build/data/palindrome_number/5.ans @@ -0,0 +1 @@ +true \ No newline at end of file diff --git a/challenges/ppc/online_judge/build/data/palindrome_number/5.in b/challenges/ppc/online_judge/build/data/palindrome_number/5.in new file mode 100644 index 0000000..0e052aa --- /dev/null +++ b/challenges/ppc/online_judge/build/data/palindrome_number/5.in @@ -0,0 +1 @@ +1425923295241 \ No newline at end of file diff --git a/challenges/ppc/online_judge/build/data/sum_multiples/1.ans b/challenges/ppc/online_judge/build/data/sum_multiples/1.ans new file mode 100644 index 0000000..b5045cc --- /dev/null +++ b/challenges/ppc/online_judge/build/data/sum_multiples/1.ans @@ -0,0 +1 @@ +21 \ No newline at end of file diff --git a/challenges/ppc/online_judge/build/data/sum_multiples/1.in b/challenges/ppc/online_judge/build/data/sum_multiples/1.in new file mode 100644 index 0000000..c793025 --- /dev/null +++ b/challenges/ppc/online_judge/build/data/sum_multiples/1.in @@ -0,0 +1 @@ +7 \ No newline at end of file diff --git a/challenges/ppc/online_judge/build/data/sum_multiples/2.ans b/challenges/ppc/online_judge/build/data/sum_multiples/2.ans new file mode 100644 index 0000000..86ee83a --- /dev/null +++ b/challenges/ppc/online_judge/build/data/sum_multiples/2.ans @@ -0,0 +1 @@ +40 \ No newline at end of file diff --git a/challenges/ppc/online_judge/build/data/sum_multiples/2.in b/challenges/ppc/online_judge/build/data/sum_multiples/2.in new file mode 100644 index 0000000..9a03714 --- /dev/null +++ b/challenges/ppc/online_judge/build/data/sum_multiples/2.in @@ -0,0 +1 @@ +10 \ No newline at end of file diff --git a/challenges/ppc/online_judge/build/data/sum_multiples/3.ans b/challenges/ppc/online_judge/build/data/sum_multiples/3.ans new file mode 100644 index 0000000..8580e7b --- /dev/null +++ b/challenges/ppc/online_judge/build/data/sum_multiples/3.ans @@ -0,0 +1 @@ +30 \ No newline at end of file diff --git a/challenges/ppc/online_judge/build/data/sum_multiples/3.in b/challenges/ppc/online_judge/build/data/sum_multiples/3.in new file mode 100644 index 0000000..f11c82a --- /dev/null +++ b/challenges/ppc/online_judge/build/data/sum_multiples/3.in @@ -0,0 +1 @@ +9 \ No newline at end of file diff --git a/challenges/ppc/online_judge/build/data/sum_multiples/4.ans b/challenges/ppc/online_judge/build/data/sum_multiples/4.ans new file mode 100644 index 0000000..5160788 --- /dev/null +++ b/challenges/ppc/online_judge/build/data/sum_multiples/4.ans @@ -0,0 +1 @@ +307 \ No newline at end of file diff --git a/challenges/ppc/online_judge/build/data/sum_multiples/4.in b/challenges/ppc/online_judge/build/data/sum_multiples/4.in new file mode 100644 index 0000000..3e932fe --- /dev/null +++ b/challenges/ppc/online_judge/build/data/sum_multiples/4.in @@ -0,0 +1 @@ +34 \ No newline at end of file diff --git a/challenges/ppc/online_judge/build/data/sum_multiples/5.ans b/challenges/ppc/online_judge/build/data/sum_multiples/5.ans new file mode 100644 index 0000000..7179a19 --- /dev/null +++ b/challenges/ppc/online_judge/build/data/sum_multiples/5.ans @@ -0,0 +1 @@ +964 \ No newline at end of file diff --git a/challenges/ppc/online_judge/build/data/sum_multiples/5.in b/challenges/ppc/online_judge/build/data/sum_multiples/5.in new file mode 100644 index 0000000..4800c7d --- /dev/null +++ b/challenges/ppc/online_judge/build/data/sum_multiples/5.in @@ -0,0 +1 @@ +58 \ No newline at end of file diff --git a/challenges/ppc/online_judge/build/data/to_lower_case/1.ans b/challenges/ppc/online_judge/build/data/to_lower_case/1.ans new file mode 100644 index 0000000..b6fc4c6 --- /dev/null +++ b/challenges/ppc/online_judge/build/data/to_lower_case/1.ans @@ -0,0 +1 @@ +hello \ No newline at end of file diff --git a/challenges/ppc/online_judge/build/data/to_lower_case/1.in b/challenges/ppc/online_judge/build/data/to_lower_case/1.in new file mode 100644 index 0000000..5ab2f8a --- /dev/null +++ b/challenges/ppc/online_judge/build/data/to_lower_case/1.in @@ -0,0 +1 @@ +Hello \ No newline at end of file diff --git a/challenges/ppc/online_judge/build/data/to_lower_case/2.ans b/challenges/ppc/online_judge/build/data/to_lower_case/2.ans new file mode 100644 index 0000000..60aecbd --- /dev/null +++ b/challenges/ppc/online_judge/build/data/to_lower_case/2.ans @@ -0,0 +1 @@ +here \ No newline at end of file diff --git a/challenges/ppc/online_judge/build/data/to_lower_case/2.in b/challenges/ppc/online_judge/build/data/to_lower_case/2.in new file mode 100644 index 0000000..60aecbd --- /dev/null +++ b/challenges/ppc/online_judge/build/data/to_lower_case/2.in @@ -0,0 +1 @@ +here \ No newline at end of file diff --git a/challenges/ppc/online_judge/build/data/to_lower_case/3.ans b/challenges/ppc/online_judge/build/data/to_lower_case/3.ans new file mode 100644 index 0000000..1940f2b --- /dev/null +++ b/challenges/ppc/online_judge/build/data/to_lower_case/3.ans @@ -0,0 +1 @@ +lovely \ No newline at end of file diff --git a/challenges/ppc/online_judge/build/data/to_lower_case/3.in b/challenges/ppc/online_judge/build/data/to_lower_case/3.in new file mode 100644 index 0000000..f6167d5 --- /dev/null +++ b/challenges/ppc/online_judge/build/data/to_lower_case/3.in @@ -0,0 +1 @@ +LOVELY \ No newline at end of file diff --git a/challenges/ppc/online_judge/build/data/to_lower_case/4.ans b/challenges/ppc/online_judge/build/data/to_lower_case/4.ans new file mode 100644 index 0000000..0f6addb --- /dev/null +++ b/challenges/ppc/online_judge/build/data/to_lower_case/4.ans @@ -0,0 +1 @@ +he110 world \ No newline at end of file diff --git a/challenges/ppc/online_judge/build/data/to_lower_case/4.in b/challenges/ppc/online_judge/build/data/to_lower_case/4.in new file mode 100644 index 0000000..4d2cb0c --- /dev/null +++ b/challenges/ppc/online_judge/build/data/to_lower_case/4.in @@ -0,0 +1 @@ +HE110 WORLD \ No newline at end of file diff --git a/challenges/ppc/online_judge/build/data/to_lower_case/5.ans b/challenges/ppc/online_judge/build/data/to_lower_case/5.ans new file mode 100644 index 0000000..7221b47 --- /dev/null +++ b/challenges/ppc/online_judge/build/data/to_lower_case/5.ans @@ -0,0 +1 @@ +l41n_w1red_w0rld \ No newline at end of file diff --git a/challenges/ppc/online_judge/build/data/to_lower_case/5.in b/challenges/ppc/online_judge/build/data/to_lower_case/5.in new file mode 100644 index 0000000..16ffca0 --- /dev/null +++ b/challenges/ppc/online_judge/build/data/to_lower_case/5.in @@ -0,0 +1 @@ +L41n_W1red_W0rld \ No newline at end of file diff --git a/challenges/ppc/online_judge/build/init.sh b/challenges/ppc/online_judge/build/init.sh index 735485b..1dcd4dd 100644 --- a/challenges/ppc/online_judge/build/init.sh +++ b/challenges/ppc/online_judge/build/init.sh @@ -3,6 +3,4 @@ echo $GZCTF_FLAG > /flag chmod 444 /flag -unset GZCTF_FLAG - -/app/oj --config /app/config.json \ No newline at end of file +/app/oj --config /app/config.json diff --git a/challenges/ppc/online_judge/build/src/job.rs b/challenges/ppc/online_judge/build/src/job.rs index 28da59d..6043353 100644 --- a/challenges/ppc/online_judge/build/src/job.rs +++ b/challenges/ppc/online_judge/build/src/job.rs @@ -9,17 +9,12 @@ use std::{ time::Duration, }; use std::string::ToString; -use lazy_static::lazy_static; use wait_timeout::ChildExt; use crate::config::Language; use crate::{config, AppError, CaseResult, Response, RunResult, State}; const TEMP_DIR_PREFIX: &str = "/tmp"; -lazy_static! { - static ref FLAG: String = env::var("GZCTF_FLAG").unwrap_or("flag{test_flag}".to_string()); - static ref FLAG_LENGTH: usize = FLAG.len(); -} // the struct represent the json content from the post job http request #[derive(Debug, Serialize, Deserialize, Clone)] @@ -208,11 +203,17 @@ impl Job { } // 返回部分 FLAG + let flag: String = env::var("GZCTF_FLAG").unwrap_or("flag{test_flag}".to_string()); + let flag_length = flag.len(); + let problem_count = config.problems.len(); - let flag_chunk_size = *FLAG_LENGTH / problem_count; - let start = (problem.id % problem_count) * flag_chunk_size; - let end = start + flag_chunk_size; - self.flag = FLAG[start..end].to_string(); + let flag_chunk_size = flag_length / problem_count; + let start = problem.id * flag_chunk_size; + let mut end = start + flag_chunk_size; + if problem.id == problem_count - 1 { + end += flag_length % problem_count; + } + self.flag = flag[start..end].to_string(); self.state = State::Finished; Ok(self.response()) diff --git a/challenges/ppc/online_judge/writeup/palindrome_number.c b/challenges/ppc/online_judge/writeup/palindrome_number.c new file mode 100644 index 0000000..c6c188a --- /dev/null +++ b/challenges/ppc/online_judge/writeup/palindrome_number.c @@ -0,0 +1,24 @@ +#include +#include + +int main() { + char buf[100]; + scanf("%99s", buf); + + int length = strlen(buf); + int ptr_left = 0; + int ptr_right = length - 1; + + while (ptr_right > ptr_left) { + if (buf[ptr_left] != buf[ptr_right]) { + printf("false"); + return 0; + } + ptr_left++; + ptr_right--; + } + + printf("true"); + return 0; +} + diff --git a/challenges/ppc/online_judge/writeup/sum_multiples.c b/challenges/ppc/online_judge/writeup/sum_multiples.c new file mode 100644 index 0000000..03aaa40 --- /dev/null +++ b/challenges/ppc/online_judge/writeup/sum_multiples.c @@ -0,0 +1,19 @@ +#include +#include + +int main() { + int num; + int result = 0; + + scanf("%d", &num); + + for (int i = 0; i <= num; i++) { + if (i % 3 == 0 || i % 5 == 0 || i % 7 == 0) { + result += i; + } + } + printf("%d", result); + + return 0; +} + diff --git a/challenges/ppc/online_judge/writeup/to_lower_case.c b/challenges/ppc/online_judge/writeup/to_lower_case.c new file mode 100644 index 0000000..8203d89 --- /dev/null +++ b/challenges/ppc/online_judge/writeup/to_lower_case.c @@ -0,0 +1,18 @@ +#include +#include + +int main() { + char s[100]; + + fgets(s, sizeof(s), stdin); + + int len = strlen(s); + for (int i = 0; i < len; ++i) { + if (s[i] >= 65 && s[i] <= 90) { + s[i] |= 32; + } + } + printf("%s", s); + return 0; +} +