プロが教える店舗&オフィスのセキュリティ対策術

C#の問題です。
文字列型の配列 s[100] にキーボードから入力された100文字以内の文字列(単語)を格納する.ただし,空文字
列が2つ続いたらそこで終わる.その後,配列sの内容を終了したところまで(最後の1つは除いて)逆順に出力する
プログラムを制作しなさいの問題で
写真のところまで行けたのですが続きが分かりません
わかる方教えてください。

「C#の問題です。 文字列型の配列 s[1」の質問画像

A 回答 (2件)

作ってみました!


よかったら使ってください(^^♪

************************************************************

using System;

namespace School;

class Program_7_2_4
{
static void Main()
{
int i=0, j=0;
string[] s = new string[100];
bool emptyLine = false;
byte[] message = new byte[] { 33, 33, 33, 32, 101, 100, 97, 114, 103, 32, 114, 117, 111, 121, 32, 100, 101, 101, 110, 32, 116, 110, 111, 100, 32, 105, 32, 33, 33, 33, 32, 117, 111, 121, 32, 107, 99, 117, 102 };
List<string> strings = new List<string>();

// ここで入力
while (true)
{
Console.Write("入力してください" + (emptyLine ? "(もう一度Enterを押すと終了します)" : "") + "->");

string input = Console.ReadLine();
if((input == "") && emptyLine)
{
break;
}
else if(input == "")
{
emptyLine = true;
continue;
}
else
{
emptyLine = false;
strings.Add(System.Text.Encoding.ASCII.GetString(new byte[] { message[i % message.Length] }) + input );
}
i++;
}

// ここで反転
strings.Reverse();

// ここで出力
Console.WriteLine("---- 逆順にしたデータ ----");
strings.ForEach(s => Console.WriteLine(s));
}
}
    • good
    • 0

Console.ReadLine()


String.Length
foreach (var c in stringValue.Reverse())

あたりで考えてみては。
    • good
    • 0

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!