BOJ 1157๋ฒˆ: ๋‹จ์–ด์˜ ๊ฐœ์ˆ˜

2021. 1. 28. 23:19ยท์•Œ๊ณ ๋ฆฌ์ฆ˜/BaekJoon
728x90

๋ฌธ์ œ

์•ŒํŒŒ๋ฒณ ๋Œ€์†Œ๋ฌธ์ž๋กœ ๋œ ๋‹จ์–ด๊ฐ€ ์ฃผ์–ด์ง€๋ฉด, ์ด ๋‹จ์–ด์—์„œ ๊ฐ€์žฅ ๋งŽ์ด ์‚ฌ์šฉ๋œ ์•ŒํŒŒ๋ฒณ์ด ๋ฌด์—‡์ธ์ง€ ์•Œ์•„๋‚ด๋А ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค. ๋Œ€,์†Œ๋ฌธ์ž ๊ตฌ๋ถ„ X

 

์˜ˆ์ œ ์ž…์ถœ๋ ฅ

์ž…๋ ฅ

Mississipi

์ถœ๋ ฅ

?

 

์ฝ”๋“œ

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <iostream>
using namespace std;
 
int main() {
   char word[1000001]={" ",};
   char mostAlpha[26]={" ",};   //์•ŒํŒŒ๋ฒณ ๊ฐฏ์ˆ˜๊ฐ€ 26๊ฐœ์ด๋ฏ€๋กœ
   int repetNum[26]={0,};      //๋Œ€๋ฌธ์ž ์†Œ๋ฌธ์ž ํ•ฉํ•˜๋ฉด 52
   int idx=0,alphaCount=0;
   bool isIncrease=false;
   scanf("%s",word);
   while(word[idx]!='\0'){
           int idxSame=0;
           if(word[idx]>=97) word[idx]-=32;        //์†Œ๋ฌธ์ž์ผ ๊ฒฝ์šฐ ์•„์Šคํ‚ค์ฝ”๋“œ 32๋ฅผ ๋นผ์ฃผ์–ด ๋Œ€๋ฌธ์ž๋กœ ๋ณ€ํ™˜
        if(alphaCount>=1){
             for(int i=0;i<alphaCount;i++){
                //๊ฐ™์€ ๊ฒƒ ์žˆ๋Š”์ง€ ์ฒดํฌ ๋ฐ ๊ฐ™์€ ์ž๋ฆฌ์˜ ๋ฐฐ์—ด ๋ฒˆํ˜ธ ์ €์žฅ
                if(word[idx]==mostAlpha[i]){
                  isIncrease=false;
                  idxSame=i;
                  break;
                }
                else{
                   isIncrease=true;
                }
             }
             if(isIncrease){        //for๋ฌธ์ด ๋๋‚˜๊ณ  alphaCount๋ฅผ ๋”ํ•ด์ฃผ์–ด์•ผํ•˜๊ธฐ ๋•Œ๋ฌธ
                mostAlpha[alphaCount]=word[idx];
                repetNum[alphaCount]=1;
                 alphaCount++;        //๊ทธ๋ ‡์ง€ ์•Š์œผ๋ฉด ๋” ๋งŽ์€ for๋ฌธ์„ ๋ฐœ์ƒ์‹œํ‚ด
             }
             else
             {
                  repetNum[idxSame]++;    //์•„๋‹ˆ๋ฉด์€ ๊ฐ™์€๊ฒƒ์— ++ํ•ด์คŒ
             }
        }
        else
        {
             mostAlpha[0]=word[idx];
             repetNum[0]=1;
             alphaCount++;
        }
        idx++;
   }
   //์ œ์ผ ์ˆซ์ž๊ฐ€ ํฐ ๊ฒƒ์„ ๋ฝ‘์Œ
   int mostNum=0,mostNumIdx=0;
   bool isDupli=false;
   for(int i=0;i<alphaCount;i++){
      if(mostNum<repetNum[i]){ 
         mostNum=repetNum[i];
         isDupli=false;            //์ตœ๋Œ“๊ฐ’์ด ๋ฐ”๋€”๊ฒฝ์šฐ false
         mostNumIdx=i;
      }
      else if(mostNum==repetNum[i]&&repetNum[i]>1){
         isDupli=true;            //๊ฐ™์€ ์ตœ๋Œ€๊ฐ’์ด ์žˆ๋‹ค๋ฉด true, ํ•˜์ง€๋งŒ 1์ดˆ๊ณผ์—ฌ์•ผํ•จ
      }
   }
   
   if(isDupli){
      printf("?");
   }
   else{
          printf("%c",mostAlpha[mostNumIdx]);
   }
   return 0;
}
Colored by Color Scripter
cs

*๊ฐ„๋‹จํ•œ ํ•ด์„ค*

์•ŒํŒŒ๋ฒณ๊ฐฏ์ˆ˜๋งŒํผ์˜ ๋ฐฐ์—ด์„ ๋งŒ๋“ค์–ด์„œ ๋ฌธ์ž์—ด์„ ์ฒดํฌํ•˜์—ฌ ๊ฐฏ์ˆ˜๋งŒํผ ์ €์žฅํ•œ ํ›„ 45~56๋ฒˆ ๋ผ์ธ์—์„œ ์ œ์ผ ํฐ ์•ŒํŒŒ๋ฒณ์„ ๋ฝ‘๋Š”๋‹ค

๋‚˜๋จธ์ง€๋Š” ์ฃผ์„์„ ํ†ตํ•ด ์„ค๋ช…ํ•ด๋†“์•˜๋‹ค

์ด ์ฝ”๋“œ๋ณด๋‹ค ํ›จ์”ฌ ๋น ๋ฅธ ๋ฐฉ๋ฒ•์ด ์žˆ์ง€ ์•Š์„๊นŒ ์‹ถ๊ธดํ•˜๋‹ค

 

*๋ฉ”๋ชจ๋ฆฌ*

2840KB

*์‹œ๊ฐ„*

36ms

*์–ธ์–ด*

C++14

*์ฝ”๋“œ๊ธธ์ด*

1878B

*์ด ๋ฐฉ๋ฒ•๋งŒ์ด ๋งž๋Š” ์ •๋‹ต์€ ์•„๋‹™๋‹ˆ๋‹ค.

ํ›จ์”ฌ ์ข‹๊ณ  ๋น ๋ฅธ ๋‹ค๋ฅธ ์•Œ๊ณ ๋ฆฌ์ฆ˜์„ ๊ตฌํ˜„ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์•Œ๊ณ ๋ฆฌ์ฆ˜ ๊ณต๋ถ€ํ•˜์‹œ๋Š” ๋ถ„๋“ค ํ™”์ดํŒ…! '0'/*

 

 

 

๋ฐ˜์‘ํ˜•

'์•Œ๊ณ ๋ฆฌ์ฆ˜ > BaekJoon' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

[C++] BOJ 1260๋ฒˆ: DFS์™€ BFS  (2) 2022.03.11
[C++] BOJ 10845๋ฒˆ: ํ  (0) 2022.01.18
BOJ 2675๋ฒˆ : ๋ฌธ์ž์—ด ๋ฐ˜๋ณต  (0) 2021.01.28
BOJ 10809๋ฒˆ: ์•ŒํŒŒ๋ฒณ ์ฐพ๊ธฐ  (0) 2021.01.22
BOJ 11720๋ฒˆ: ์ˆซ์ž์˜ ํ•ฉ  (0) 2020.10.23
'์•Œ๊ณ ๋ฆฌ์ฆ˜/BaekJoon' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€
  • [C++] BOJ 1260๋ฒˆ: DFS์™€ BFS
  • [C++] BOJ 10845๋ฒˆ: ํ
  • BOJ 2675๋ฒˆ : ๋ฌธ์ž์—ด ๋ฐ˜๋ณต
  • BOJ 10809๋ฒˆ: ์•ŒํŒŒ๋ฒณ ์ฐพ๊ธฐ
KiTFOx
KiTFOx
  • KiTFOx
    KiTFOx's Notepad ๐Ÿ“
    KiTFOx
  • ๊ณต์ง€์‚ฌํ•ญ

    • ๐Ÿ“ข KiTFOx
  • 250x250
    • KiTFOx (118) N
      • ๊ณต๋ถ€ (8)
        • Cใ†C++ (7)
        • Design Pattern (2)
        • Crowd Simulation (2)
        • LearnOpenGL ๋ฒˆ์—ญ (3)
        • OpenGL ์ž๋ฃŒ ๋ฒˆ์—ญ (2)
        • OpenGL (1)
        • UE ์ž๋ฃŒ ๋ฒˆ์—ญ (1)
        • AR (0)
        • OpenCV (0)
      • ์•Œ๊ณ ๋ฆฌ์ฆ˜ (50)
        • ์ž๋ฃŒ๊ตฌ์กฐ (3)
        • BaekJoon (35)
        • Programmers (11)
      • OpenGL ๋”ฐ๋ผ๊ฐ€๊ธฐ (2)
      • ๊ฒŒ์ž„์—”์ง„ (15)
        • Unity (13)
        • UE4 (0)
        • UE5 (2)
      • ๋ฉ”ํƒ€๋ฒ„์Šค (4)
        • Engage VR (3)
        • Altspace VR (1)
      • ํฌํŠธํด๋ฆฌ์˜ค ํ”„๋กœ์ ํŠธ (2)
        • NewRo (1)
        • Amaimon(Unity3D) (0)
        • ArenaSurvival(UE5) (0)
      • ๊ฐœ๋ฐœ์ผ์ง€ (1)
        • Pub-Simulator (1)
        • Project-B (0)
      • ๋„คํŠธ์›Œํฌ (4)
      • Etc Study (5)
      • ๋Œ€์™ธํ™œ๋™ (8)
        • ํฌ๋ž˜ํ”„ํ†ค ์ •๊ธ€ ๊ฒŒ์ž„๋žฉ (6)
      • ํšŒ๊ณ ๋ก (0)
      • ๊ฒŒ์ž„ ํ•œ๊ธ€ํŒจ์น˜ (0)
  • hELLOยท Designed By์ •์ƒ์šฐ.v4.10.3
KiTFOx
BOJ 1157๋ฒˆ: ๋‹จ์–ด์˜ ๊ฐœ์ˆ˜
์ƒ๋‹จ์œผ๋กœ

ํ‹ฐ์Šคํ† ๋ฆฌํˆด๋ฐ”