문제링크
https://www.acmicpc.net/problem/2941
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String str = br.readLine();
str = str.replace("c=", "0");
str = str.replace("c-", "1");
str = str.replace("dz=", "2");
str = str.replace("d-", "3");
str = str.replace("lj", "4");
str = str.replace("nj", "5");
str = str.replace("s=", "6");
str = str.replace("z=", "7");
System.out.println(str.length());
}
}
#include <stdio.h>
#include <string.h>
int main()
{
char str[101];
int sum = 0;
scanf("%s", str);
for (int i = 0; i < strlen(str); i++)
{
if (str[i] == 'c')
{
if (str[i + 1] == '=' || str[i + 1] == '-')
{
i = i + 1;
}
}
else if (str[i] == 'd')
{
if (str[i + 1] == '-')
{
i += 1;
}
else if (str[i + 1] == 'z' && str[i + 2] == '=')
{
i += 2;
}
}
else if (str[i] == 'l' || str[i] == 'n')
{
if (str[i + 1] == 'j')
{
i += 1;
}
}
else if (str[i] == 's' || str[i] == 'z')
{
if (str[i + 1] == '=')
{
i += 1;
}
}
sum++;
}
printf("%d\n", sum);
return 0;
}
'알고리즘 > 백준' 카테고리의 다른 글
[JAVA]백준_2851_슈퍼 마리오 (0) | 2021.02.25 |
---|---|
[JAVA]백준_2559_수열 (0) | 2021.02.25 |
[JAVA]백준_2578_빙고 (0) | 2021.02.25 |
[JAVA]백준_10157_자리배정 (0) | 2021.02.25 |
[JAVA]백준_14696_딱지놀이 (0) | 2021.02.23 |