๋ชฉ์ฐจ
1. ๋ฌธ์
2. ๋ง์ถ์ฝ๋
/*
์ํ๋ฒณ ๋์๋ฌธ์ ๋จ์ด์์ ๊ฐ์ฅ๋ง์ด ์ฌ์ฉ๋ ์ํ๋ฒณ(๋์๋ฌธ์ ๊ตฌ๋ถX)
*/
import java.io.IOException;
public class bj1157{
public static void main(String[] args) throws IOException{
int[] arr = new int[26]; // ์๋ฌธ์์ ๊ฐ์๋ 26๊ฐ
int c = System.in.read();
while (c > 64) { // ๊ณต๋ฐฑ์ ์
๋ ฅ๋ฐ๋ ์๊ฐ ์ข
๋ฃ
if (c < 91) {
arr[c - 65]++;
} else {
arr[c - 97]++;
}
c = System.in.read();
}
int max = -1;
int ch = -2; // ? ๋ 63
for (int i = 0; i < 26; i++) {
if (arr[i] > max) {
max = arr[i];
ch = i;
} else if (arr[i] == max) {
ch = -2;
}
}
System.out.print((char) (ch+65));
}
}
3. ํ๋ฆฐ์ฝ๋: ์๊ฐ์ด๊ณผ
/*
์ํ๋ฒณ ๋์๋ฌธ์ ๋จ์ด์์ ๊ฐ์ฅ๋ง์ด ์ฌ์ฉ๋ ์ํ๋ฒณ(๋์๋ฌธ์ ๊ตฌ๋ถX)
*/
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
public class bj1157{
public static void main(String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String s = br.readLine().toUpperCase();
char[] txtMax = new char[]{s.charAt(0),s.charAt(0)};
int[] cMax = new int[]{0,0};
int count;
for (int i=0; i<s.length(); i++)
{
count = 0;
if(i!=0 && txtMax[0] == s.charAt(i))
{
continue;
}
for(int j=i; j<s.length(); j++)
{
if(s.charAt(i)==s.charAt(j))
{
count++;
}
}
if(cMax[0]<count)
{
txtMax[0] = s.charAt(i);
cMax[0] = count;
}else if(cMax[0]==count)
{
txtMax[1] = s.charAt(i);
cMax[1] = count;
}
}
if(cMax[0] == cMax[1])
{
System.out.println("?");
}else{
System.out.println(txtMax[0]);
}
}
}
4. ์ฐธ์กฐ
'๐ป ๋ฌธ์ ํ๊ณ ์ ๋ฆฌํ๊ธฐ + > ๋ฐฑ์ค' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[๋ฐฑ์ค Java] 1316: ๊ทธ๋ฃน ๋จ์ด ์ฒด์ปค (0) | 2023.09.24 |
---|---|
[๋ฐฑ์ค Java] 5622: ํฌ๋ก์ํฐ์ ์ํ๋ฒณ (0) | 2023.09.24 |
[๋ฐฑ์ค Java] 10988: ํฐ๋ฆฐ๋๋กฌ์ธ์ง ํ์ธํ๊ธฐ (0) | 2023.09.24 |
[๋ฐฑ์ค Java] 2444: ๋ณ ์ฐ๊ธฐ - 7 (0) | 2023.09.23 |
[๋ฐฑ์ค Java] 3003: ํน, ํธ, ๋ฃฉ, ๋น์, ๋์ดํธ, ํฐ (2) | 2023.09.23 |