文字列関数を使用せずにC#でループ文を使用せずに文字列がパリンドロームかどうかをチェックする。私は文字列関数なしで行うことができますが、私はループステートメントなしでチェックする方法を知らない。私はインタビューの1つでこの問題に直面しています。文字列関数を使用せずにC#でループ文を使用しないで文字列がパリンドロムかどうかを確認する
using System;
namespace palindrome
{
class Program
{
static void Main(string[] args)
{
string s,revs="";
Console.WriteLine(" Enter string");
s = Console.ReadLine();
for (int i = s.Length-1; i >=0; i--) //**i want to replace this for loop**
{
revs += s[i].ToString();
}
if (revs == s) // Checking whether string is palindrome or not
{
Console.WriteLine("String is Palindrome \n Entered String Was {0} and reverse string is {1}", s, revs);
}
else
{
Console.WriteLine("String is not Palindrome \n Entered String Was {0} and reverse string is {1}", s, revs);
}
Console.ReadKey();
}
}
}
"文字列関数を使用しない"とは何を意味しているのかは不明ですが、 '.Length'と' [] 'を使用することが許されている場合は、再帰でこれを行うことができます。 –
[C++バージョン](http://stackoverflow.com/questions/34257983/how-to-check-if-string-is-palindrome-without-using-string-functions-in-c) – stuartd
与えられた答えは? – fubo