#include <stdio.h>
int main(void)
{
// [2] 問題1・入力した文字列から文字を一文字ずつ交互に読み取り、文字列1、文字列2として結果を出力するプログラムを作成せよ。
{
char s[1000], s1[500], s2[500];
int i = 0, j = 0;
printf("文字列・");
scanf("%s", s);
while (1)
{
if (!s[i])break;
s1[j] = s[i++];
s1[i] = '\0';
if (!s[i])break;
s2[j] = s[i++];
s2[i] = '\0';
j++;
}
printf("文字列1・%s\n", s1);
printf("文字列2・%s\n", s2);
}
// 問題2・また、文字列1、文字列2を入力し、それぞれから一文字ずつ交互に読み取った結果を文字列として出力するプログラムを作成せよ。
{
int i = 0, j = 0;
char s[1000], s1[500], s2[500];
printf("文字列1・");
scanf("%s", s1);
printf("文字列2・");
scanf("%s", s2);
printf("文字列・");
while (s1[i] | s2[j])
{
if (s1[i])
printf("%c", s1[i++]);
if (s2[j])
printf("%c", s2[j++]);
}
printf("\n");
}
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CgppbnQgbWFpbih2b2lkKQp7CiAgICAvLyBbMl0g5ZWP6aGMMeODu+WFpeWKm+OBl+OBn+aWh+Wtl+WIl+OBi+OCieaWh+Wtl+OCkuS4gOaWh+Wtl+OBmuOBpOS6pOS6kuOBq+iqreOBv+WPluOCiuOAgeaWh+Wtl+WIlzHjgIHmloflrZfliJcy44Go44GX44Gm57WQ5p6c44KS5Ye65Yqb44GZ44KL44OX44Ot44Kw44Op44Og44KS5L2c5oiQ44Gb44KI44CCCiAgICB7CiAgICAgICAgY2hhciBzWzEwMDBdLCBzMVs1MDBdLCBzMls1MDBdOwogICAgICAgIGludCBpID0gMCwgaiA9IDA7CiAgICAgICAgcHJpbnRmKCLmloflrZfliJfjg7siKTsKICAgICAgICBzY2FuZigiJXMiLCBzKTsKICAgICAgICB3aGlsZSAoMSkKICAgICAgICB7CiAgICAgICAgICAgIGlmICghc1tpXSlicmVhazsKICAgICAgICAgICAgczFbal0gPSBzW2krK107CiAgICAgICAgICAgIHMxW2ldID0gJ1wwJzsKICAgICAgICAgICAgaWYgKCFzW2ldKWJyZWFrOwogICAgICAgICAgICBzMltqXSA9IHNbaSsrXTsKICAgICAgICAgICAgczJbaV0gPSAnXDAnOwogICAgICAgICAgICBqKys7CiAgICAgICAgfQoKICAgICAgICBwcmludGYoIuaWh+Wtl+WIlzHjg7slc1xuIiwgczEpOwogICAgICAgIHByaW50Zigi5paH5a2X5YiXMuODuyVzXG4iLCBzMik7CiAgICB9CiAgICAvLyDllY/poYwy44O744G+44Gf44CB5paH5a2X5YiXMeOAgeaWh+Wtl+WIlzLjgpLlhaXlipvjgZfjgIHjgZ3jgozjgZ7jgozjgYvjgonkuIDmloflrZfjgZrjgaTkuqTkupLjgavoqq3jgb/lj5bjgaPjgZ/ntZDmnpzjgpLmloflrZfliJfjgajjgZfjgablh7rlipvjgZnjgovjg5fjg63jgrDjg6njg6DjgpLkvZzmiJDjgZvjgojjgIIKICAgIHsKICAgICAgICBpbnQgaSA9IDAsIGogPSAwOwogICAgICAgIGNoYXIgc1sxMDAwXSwgczFbNTAwXSwgczJbNTAwXTsKICAgICAgICBwcmludGYoIuaWh+Wtl+WIlzHjg7siKTsKICAgICAgICBzY2FuZigiJXMiLCBzMSk7CiAgICAgICAgcHJpbnRmKCLmloflrZfliJcy44O7Iik7CiAgICAgICAgc2NhbmYoIiVzIiwgczIpOwogICAgICAgIHByaW50Zigi5paH5a2X5YiX44O7Iik7CiAgICAgICAgd2hpbGUgKHMxW2ldIHwgczJbal0pCiAgICAgICAgewogICAgICAgICAgICBpZiAoczFbaV0pCiAgICAgICAgICAgICAgICBwcmludGYoIiVjIiwgczFbaSsrXSk7CiAgICAgICAgICAgIGlmIChzMltqXSkKICAgICAgICAgICAgICAgIHByaW50ZigiJWMiLCBzMltqKytdKTsKICAgICAgICB9CiAgICAgICAgcHJpbnRmKCJcbiIpOwogICAgfQoKICAgIHJldHVybiAwOwp9Cg==