알고리즘
프로그래머스 C# 크기가 작은 부분 문자
하길
2024. 6. 27. 02:16
문제설명
해결방안
using System;
public class Solution {
public int solution(string t, string p) {
int answer = 0;
long num = 0;
for(int i = 0; i < t.Length - p.Length + 1; i++)
{
num = long.Parse(t.Substring(i, p.Length));
if(num <= long.Parse(p)) { answer++; }
}
return answer;
}
}
Substring 함수를 이용하면 특정위치부터 원하는 길이까지 문자열을 자를 수 있다.