From 50ea136fdb3220b671d8fc186923255a31794e05 Mon Sep 17 00:00:00 2001 From: Luthics Date: Sun, 19 Feb 2023 14:12:36 +0800 Subject: [PATCH] =?UTF-8?q?=E5=89=8D5=E9=A2=98=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vscode/settings.json | 62 ++++++++++++++++++++++++++++++++++++++++++- 1/3.c | 25 ++++++++--------- 1/4.c | 38 ++++++++++++++++++++++++++ 1/5.c | 38 ++++++++++++++++++++++++++ 4 files changed, 148 insertions(+), 15 deletions(-) create mode 100644 1/4.c create mode 100644 1/5.c diff --git a/.vscode/settings.json b/.vscode/settings.json index 194ffa4..4d3e3a4 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -2,5 +2,65 @@ "C_Cpp.clang_format_style": "{ BasedOnStyle: Chromium, UseTab: Never, IndentWidth: 4, TabWidth: 4, AllowShortIfStatementsOnASingleLine: false, IndentCaseLabels: false, ColumnLimit: 0, AccessModifierOffset: -4, NamespaceIndentation: All, FixNamespaceComments: false }", "files.associations": { "stdio.h": "c" - } + }, + "code-runner.executorMap": { + "javascript": "node", + "java": "cd $dir && javac $fileName && java $fileNameWithoutExt", + "c": "cd $dir && gcc -std=c11 $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt", + "cpp": "cd $dir && g++ $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt", + "objective-c": "cd $dir && gcc -framework Cocoa $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt", + "php": "php", + "python": "python -u", + "perl": "perl", + "perl6": "perl6", + "ruby": "ruby", + "go": "go run", + "lua": "lua", + "groovy": "groovy", + "powershell": "powershell -ExecutionPolicy ByPass -File", + "bat": "cmd /c", + "shellscript": "bash", + "fsharp": "fsi", + "csharp": "scriptcs", + "vbscript": "cscript //Nologo", + "typescript": "ts-node", + "coffeescript": "coffee", + "scala": "scala", + "swift": "swift", + "julia": "julia", + "crystal": "crystal", + "ocaml": "ocaml", + "r": "Rscript", + "applescript": "osascript", + "clojure": "lein exec", + "haxe": "haxe --cwd $dirWithoutTrailingSlash --run $fileNameWithoutExt", + "rust": "cd $dir && rustc $fileName && $dir$fileNameWithoutExt", + "racket": "racket", + "scheme": "csi -script", + "ahk": "autohotkey", + "autoit": "autoit3", + "dart": "dart", + "pascal": "cd $dir && fpc $fileName && $dir$fileNameWithoutExt", + "d": "cd $dir && dmd $fileName && $dir$fileNameWithoutExt", + "haskell": "runhaskell", + "nim": "nim compile --verbosity:0 --hints:off --run", + "lisp": "sbcl --script", + "kit": "kitc --run", + "v": "v run", + "sass": "sass --style expanded", + "scss": "scss --style expanded", + "less": "cd $dir && lessc $fileName $fileNameWithoutExt.css", + "FortranFreeForm": "cd $dir && gfortran $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt", + "fortran-modern": "cd $dir && gfortran $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt", + "fortran_fixed-form": "cd $dir && gfortran $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt", + "fortran": "cd $dir && gfortran $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt", + "sml": "cd $dir && sml $fileName" + }, + "C_Cpp.default.compilerArgs": [ + "-g", + "${file}", + "-std=c11", + "-o", + "${fileDirname}/${fileBasenameNoExtension}" + ] } \ No newline at end of file diff --git a/1/3.c b/1/3.c index 6381329..7318dbc 100644 --- a/1/3.c +++ b/1/3.c @@ -1,19 +1,16 @@ #include +struct student { + int id; + float x, y, z; +} stu[3]; + int main() { - // printf(" 1.Input\n"); - // printf(" 2.Output\n"); - // printf(" 3.Order\n"); - // printf(" 4.Quit\n"); - char m; - scanf("%c", &m); - if (m == 'I') - printf("You are trying to input info"); - else if (m == 'O') - printf("You are trying to output info"); - else if (m == 'D') - printf("You are trying to make things ordered"); - else if (m == 'Q') - printf("You are about to quit"); + scanf("%d,%f,%f,%f", &stu[0].id, &stu[0].x, &stu[0].y, &stu[0].z); + scanf("%d,%f,%f,%f", &stu[1].id, &stu[1].x, &stu[1].y, &stu[1].z); + scanf("%d,%f,%f,%f", &stu[2].id, &stu[2].x, &stu[2].y, &stu[2].z); + printf("%d,%7.1f,%7.1f,%7.1f\n", stu[0].id, stu[0].x, stu[0].y, stu[0].z); + printf("%d,%7.1f,%7.1f,%7.1f\n", stu[1].id, stu[1].x, stu[1].y, stu[1].z); + printf("%d,%7.1f,%7.1f,%7.1f", stu[2].id, stu[2].x, stu[2].y, stu[2].z); return 0; } \ No newline at end of file diff --git a/1/4.c b/1/4.c new file mode 100644 index 0000000..15a93d6 --- /dev/null +++ b/1/4.c @@ -0,0 +1,38 @@ +#include + +struct student { + int id; + float x, y, z; + float sum; +} stu[3]; + +void swap(struct student* a, struct student* b) { + struct student c; + c = *a; + *a = *b; + *b = c; +} + +void sort() { + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3 - i - 1; j++) { + if (stu[j].sum < stu[j + 1].sum) { + swap(&stu[j], &stu[j + 1]); + } + } + } +} + +int main() { + scanf("%d,%f,%f,%f", &stu[0].id, &stu[0].x, &stu[0].y, &stu[0].z); + scanf("%d,%f,%f,%f", &stu[1].id, &stu[1].x, &stu[1].y, &stu[1].z); + scanf("%d,%f,%f,%f", &stu[2].id, &stu[2].x, &stu[2].y, &stu[2].z); + stu[0].sum = stu[0].x + stu[0].y + stu[0].z; + stu[1].sum = stu[1].x + stu[1].y + stu[1].z; + stu[2].sum = stu[2].x + stu[2].y + stu[2].z; + sort(); + printf("%d,%.1f\n", stu[0].id, stu[0].sum); + printf("%d,%.1f\n", stu[1].id, stu[1].sum); + printf("%d,%.1f\n", stu[2].id, stu[2].sum); + return 0; +} \ No newline at end of file diff --git a/1/5.c b/1/5.c new file mode 100644 index 0000000..8b6e83e --- /dev/null +++ b/1/5.c @@ -0,0 +1,38 @@ +#include + +struct student { + int id, c; + float x, y, z; + float sum; +} stu[3]; + +void swap(struct student* a, struct student* b) { + struct student c; + c = *a; + *a = *b; + *b = c; +} + +void sort() { + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3 - i - 1; j++) { + if (stu[j].c > stu[j + 1].c || (stu[j].c == stu[j + 1].c && stu[j].sum < stu[j + 1].sum)) { + swap(&stu[j], &stu[j + 1]); + } + } + } +} + +int main() { + scanf("%d,%d,%f,%f,%f", &stu[0].c, &stu[0].id, &stu[0].x, &stu[0].y, &stu[0].z); + scanf("%d,%d,%f,%f,%f", &stu[1].c, &stu[1].id, &stu[1].x, &stu[1].y, &stu[1].z); + scanf("%d,%d,%f,%f,%f", &stu[2].c, &stu[2].id, &stu[2].x, &stu[2].y, &stu[2].z); + stu[0].sum = stu[0].x + stu[0].y + stu[0].z; + stu[1].sum = stu[1].x + stu[1].y + stu[1].z; + stu[2].sum = stu[2].x + stu[2].y + stu[2].z; + sort(); + printf("%d,%d,%.1f\n", stu[0].c, stu[0].id, stu[0].sum); + printf("%d,%d,%.1f\n", stu[1].c, stu[1].id, stu[1].sum); + printf("%d,%d,%.1f\n", stu[2].c, stu[2].id, stu[2].sum); + return 0; +} \ No newline at end of file