C#에서 루프 함수를 사용하지 않고 문자열 함수를 사용하지 않고 문자열이 palindrome인지 여부를 확인하십시오. 문자열 함수없이 할 수 있지만 루프 문없이 확인하는 방법을 모르겠습니다. 인터뷰 중 하나에서이 질문에 직면합니다.C#에서 루프 문을 사용하지 않고 문자열 함수를 사용하지 않고 문자열이 palindrome인지 여부를 확인하십시오.
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