עבור לתוכן
View in the app

A better way to browse. Learn more.

HWzone

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

צריך עזרה - פלינדרום בסטרינג, מערך סטרינג[#C]

Featured Replies

פורסם

מתוך שיעורי בית:

קבל משתנה מסוג STRING חפש את כל אפשוריות הפלינדרום שבו (פלינדרום זה -abcba , 123321)

הדפס את הפלינדרום הארוך ביותר ואת אורכו.

אני חושב שהצלחתי חלקית את התרגיל - אבל יש לי בעיה לגבי מערך סטריגנים, איך מגדירים את האורך של המערך בלי לדעת מה יהיה האורך שלו ? כי האורך תלוי במספר החלקים בסטרינג בהם יש שני תווים זהים , כמו [glow=red,2,300]A[/glow]vnjxcvhjxcv[glow=red,2,300]A[/glow]

עריכה: הצלחתי , הבעיה היתה כשהאורך של המערך הראשון לא הספיק לאורך של המערך השני (שנשלח לבדיקה) , אבל אם מכפילים את האורך בריבוע האורך של המערך הראשוני (כי אלו סה"כ האפשרויות) אז זה עובד.

אשמח לאפשוריות לייעל את התוכנית , כי כרגע היא לא ממש יעילה :P

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
public static bool Palindrom(string str)
{
for (int i = 0; i < str.Length / 2; i++)
{
if (str[i] != str[str.Length - 1 - i])
return false;
}
return true;
}
public static string[] Check(string str)
{
int counter = 0;
string sstr;
string[] sstrArr = new string[str.Length];
for (int i = 0; i < str.Length - 1; i++)
{
for (int j = (1 + i); j < str.Length; j++)
{
if (str[i] == str[j])
{
sstr = str.Substring(i, (j - i) + 1);
Console.WriteLine(sstr);
if(counter < str.Length)
{
sstrArr[counter] = sstr;
counter++;
}
}
}
}
return sstrArr;
}
static void Main(string[] args)
{
Console.WriteLine("Palindrom- Inster String");
string str = Console.ReadLine();
string[] strAAr = Check(str);
bool flag; int longestL=0,L, Position=0;
for (int i = 0; i < strAAr.Length; i++)
{
if (strAAr[i] != null)
{
flag=Palindrom(strAAr[i]);
if (flag)
{
L = (strAAr[i]).Length;
if (L > longestL)
{
longestL = L;
Position = i;
}

}

Console.WriteLine(strAAr[i]);
}
}
if (longestL != 0)
Console.WriteLine("The Longest Palidrom is: '{0}' it's length is {1}", strAAr[Position], longestL);
else
Console.WriteLine("NO PALINDROM FOUND!");

}
}
}

פורסם

פתרון פשוט מאוד - אל תעבוד עם מערך, תעבוד עם List.

פורסם
  • מחבר

אתה יכול להסביר בבקשה בקצרה איך הפקודה עובדת ?

ארכיון

דיון זה הועבר לארכיון ולא ניתן להוסיף בו תגובות חדשות.

דיונים חדשים

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.