generated from kenryuS/report-temp
Compare commits
2 Commits
bddcc77361
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 03fc9322f4 | |||
| 494e7b51bb |
Binary file not shown.
|
After Width: | Height: | Size: 21 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 37 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 14 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 14 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 12 KiB |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,68 @@
|
||||
\documentclass[xelatex,a4paper,11pt,ja=standard]{bxjsarticle}
|
||||
|
||||
\usepackage{tex/preamble}
|
||||
\usepackage{tex/simple-title}
|
||||
|
||||
\reportauthor{柴田健琉}
|
||||
\reporttitle{情報処理2 - 前期第5回課題}
|
||||
\reportdate{2026年}{05月}{21日}
|
||||
\turnindate{2026年}{05月}{21日}
|
||||
|
||||
\begin{document}
|
||||
\simpletitle{}
|
||||
|
||||
\section{はじめに}
|
||||
|
||||
この課題のプログラムは以下の環境での動作が確認されている:
|
||||
|
||||
\begin{itemize}
|
||||
\item {OS: NixOS 25.11 Xantusia, Linux 7.0.6 x86\_64}
|
||||
\item {CC: GCC 15.2.0}
|
||||
\item {CFLAGS: \texttt{-g -O1 -Wall -Wpedantic}}
|
||||
\item {ファイルエンコーディング: UTF-8}
|
||||
\end{itemize}
|
||||
|
||||
\section{課題1}
|
||||
|
||||
与えられた文字列内を探索し,特定の文字の最初に表れる添字を返す関数\texttt{str\_char}を作成する,
|
||||
|
||||
\lstinputlisting[language=C,title={課題1のプログラム}]{./src/cls05/a1.c}
|
||||
|
||||
\subsection{実行結果}
|
||||
|
||||
\begin{figure}[tbh]
|
||||
\centering
|
||||
\includegraphics[width=12cm]{./assets/cls05-a1.png}
|
||||
\caption{課題1の実行結果}
|
||||
\end{figure}
|
||||
|
||||
\section{課題2}
|
||||
|
||||
入力された文字列の文字と文字コードを表示するプログラム,なお文字列の入力には\texttt{getchar}関数を用いること.
|
||||
|
||||
\lstinputlisting[language=C,title={課題2のプログラム}]{./src/cls05/a2.c}
|
||||
|
||||
\subsection{実行結果}
|
||||
|
||||
\begin{figure}[tbh]
|
||||
\centering
|
||||
\includegraphics[width=12cm]{./assets/cls05-a2.png}
|
||||
\caption{課題2の実行結果}
|
||||
\end{figure}
|
||||
|
||||
\section{課題3}
|
||||
|
||||
入力した文字列の並びを反転させる関数\texttt{rev\_string}を作成する.
|
||||
|
||||
\lstinputlisting[language=C,title={課題3のプログラム}]{./src/cls05/a3.c}
|
||||
|
||||
\newpage
|
||||
|
||||
\subsection{実行結果}
|
||||
|
||||
\begin{figure}[tbh]
|
||||
\centering
|
||||
\includegraphics[width=12cm]{./assets/cls05-a3.png}
|
||||
\caption{課題3のプログラム}
|
||||
\end{figure}
|
||||
\end{document}
|
||||
@@ -0,0 +1,51 @@
|
||||
\documentclass[xelatex,a4paper,11pt,ja=standard]{bxjsarticle}
|
||||
|
||||
\usepackage{tex/preamble}
|
||||
\usepackage{tex/simple-title}
|
||||
|
||||
\reportauthor{柴田健琉}
|
||||
\reporttitle{情報処理2 - 前期第6回課題}
|
||||
\reportdate{2026年}{05月}{25日}
|
||||
\turnindate{2026年}{05月}{25日}
|
||||
|
||||
\begin{document}
|
||||
\simpletitle
|
||||
|
||||
\section{はじめに}
|
||||
|
||||
この課題のプログラムは以下の環境での動作が確認されている:
|
||||
|
||||
\begin{itemize}
|
||||
\item {OS: NixOS 25.11 Xantusia, Linux 7.0.9 x86\_64}
|
||||
\item {CC: GCC 15.2.0}
|
||||
\item {CFLAGS: \texttt{-g -O1 -Wall -Wpedantic}}
|
||||
\end{itemize}
|
||||
|
||||
\section{課題1}
|
||||
|
||||
入力した文字列\texttt{s}内に特定の文字\texttt{c}の出現回数を返す関数\texttt{str\_chnum}を作成する.
|
||||
|
||||
\lstinputlisting[language=C,title={課題1のプログラム}]{./src/cls06/a1.c}
|
||||
|
||||
\subsection{実行結果}
|
||||
|
||||
\begin{figure}[tbh]
|
||||
\centering
|
||||
\includegraphics[width=12cm]{./assets/cls06-a1.png}
|
||||
\caption{課題1の実行結果}
|
||||
\end{figure}
|
||||
|
||||
\section{課題2}
|
||||
|
||||
入力した文字列\texttt{s}を\texttt{n}回連続で出力するサブルーティーン\texttt{put\_stringn}を作成する.
|
||||
|
||||
\lstinputlisting[language=C,title={課題2のプログラム}]{./src/cls06/a2.c}
|
||||
|
||||
\subsection{実行結果}
|
||||
|
||||
\begin{figure}[tbh]
|
||||
\centering
|
||||
\includegraphics[width=12cm]{./assets/cls06-a2.png}
|
||||
\caption{課題2の実行結果}
|
||||
\end{figure}
|
||||
\end{document}
|
||||
@@ -0,0 +1,14 @@
|
||||
include ../common.mk
|
||||
|
||||
PROJECT_NAME:=cls05
|
||||
|
||||
TGTS:=$(patsubst %.c,%,$(wildcard *.c))
|
||||
|
||||
all: $(TGTS)
|
||||
|
||||
%: %.c
|
||||
@mkdir -p $(BUILD_PATH)/$(PROJECT_NAME)
|
||||
$(CC) $(CFLAGS) -I. $^ -o $(BUILD_PATH)/$(PROJECT_NAME)/$@
|
||||
|
||||
clean:
|
||||
$(RM) -drf $(BUILD_PATH)/$(PROJECT_NAME)
|
||||
@@ -0,0 +1,38 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#define BUFF_SZ 256
|
||||
|
||||
int str_char(const char s[], int c) {
|
||||
int idx = 0;
|
||||
while (s[idx] != '\0') {
|
||||
if (s[idx] == (char)c) {
|
||||
return idx + 1;
|
||||
}
|
||||
idx++;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
char buff[BUFF_SZ] = {0};
|
||||
char query = 0;
|
||||
|
||||
printf("Input String: ");
|
||||
fgets(buff, BUFF_SZ, stdin);
|
||||
|
||||
printf("Input Search Character: ");
|
||||
scanf("%c", &query);
|
||||
|
||||
printf("%c, %s\n", query, buff);
|
||||
|
||||
int ret = str_char(buff, query);
|
||||
if (ret != -1) {
|
||||
printf("Found %c at %d\n", query, ret);
|
||||
} else {
|
||||
printf("Queried character not found.\n");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#define BUFF_SZ 256
|
||||
|
||||
int main(void) {
|
||||
char buff[BUFF_SZ] = {0};
|
||||
int cnt = 0;
|
||||
|
||||
printf("Input String: ");
|
||||
while ((buff[cnt] = getchar()) != '\n') {
|
||||
cnt++;
|
||||
};
|
||||
buff[cnt] = '\0';
|
||||
|
||||
int i = 0;
|
||||
while (buff[i] != '\0') {
|
||||
printf(
|
||||
"Char: %c, ASCII Code: 0x%X (%d)\n",
|
||||
buff[i], (int)buff[i], (int)buff[i]
|
||||
);
|
||||
i++;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#define BUFF_SZ 256
|
||||
|
||||
void rev_string(char s[]) {
|
||||
int str_sz = 0;
|
||||
char tmp = 0;
|
||||
|
||||
do {
|
||||
str_sz++;
|
||||
} while (s[str_sz] != '\0' && str_sz < BUFF_SZ);
|
||||
str_sz--; // remove null terminater from count
|
||||
|
||||
for (int i = 0; i < str_sz/2; i++) {
|
||||
tmp = s[str_sz - 1 - i];
|
||||
s[str_sz - 1 - i] = s[i];
|
||||
s[i] = tmp;
|
||||
}
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
char buff[BUFF_SZ] = {0};
|
||||
|
||||
printf("Input String: ");
|
||||
fgets(buff, BUFF_SZ, stdin);
|
||||
|
||||
printf("Got: %s\n", buff);
|
||||
|
||||
rev_string(buff);
|
||||
|
||||
printf("Rev: %s\n", buff);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
include ../common.mk
|
||||
|
||||
PROJECT_NAME:=cls06
|
||||
|
||||
TGTS:=$(patsubst %.c,%,$(wildcard *.c))
|
||||
|
||||
all: $(TGTS)
|
||||
|
||||
%: %.c
|
||||
@mkdir -p $(BUILD_PATH)/$(PROJECT_NAME)
|
||||
$(CC) $(CFLAGS) $^ -o $(BUILD_PATH)/$(PROJECT_NAME)/$@
|
||||
|
||||
clean:
|
||||
$(RM) -drf $(BUILD_PATH)/$(PROJECT_NAME)
|
||||
@@ -0,0 +1,37 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define BUFF_SZ 256
|
||||
|
||||
int str_chnum(const char s[], int c) {
|
||||
int idx = 0;
|
||||
int n = 0;
|
||||
|
||||
while (s[idx] != '\0' && idx < BUFF_SZ) {
|
||||
if (s[idx] == (char)c) {
|
||||
n++;
|
||||
}
|
||||
idx++;
|
||||
}
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
char *buff = (char*)calloc(sizeof(char), BUFF_SZ);
|
||||
char query = 0;
|
||||
|
||||
printf("Input String: ");
|
||||
fgets(buff, BUFF_SZ, stdin);
|
||||
|
||||
printf("Input Search Character: ");
|
||||
scanf("%c", &query);
|
||||
|
||||
int cnt = str_chnum(buff, query);
|
||||
|
||||
printf("Found %d \'%c\'\n", cnt, query, buff);
|
||||
|
||||
free(buff);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define BUFF_SZ 256
|
||||
|
||||
void put_stringn(const char s[], int n) {
|
||||
if (n < 0) return;
|
||||
|
||||
int idx = 0;
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
idx = 0;
|
||||
while (s[idx] != '\0' && idx < BUFF_SZ) {
|
||||
if (s[idx] == '\n') {
|
||||
idx++;
|
||||
continue;
|
||||
}
|
||||
putchar(s[idx]);
|
||||
idx++;
|
||||
}
|
||||
}
|
||||
|
||||
putchar('\0');
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
char *buff = (char*)calloc(sizeof(char), BUFF_SZ);
|
||||
int n = 0;
|
||||
|
||||
printf("Input String: ");
|
||||
fgets(buff, BUFF_SZ, stdin);
|
||||
|
||||
printf("Input Repeat Num: ");
|
||||
scanf("%d", &n);
|
||||
|
||||
put_stringn(buff, n);
|
||||
putchar('\n');
|
||||
|
||||
free(buff);
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user