# 16968 / ์ฐจ๋Ÿ‰ ๋ฒˆํ˜ธํŒ 1
Study Repository

16968 / ์ฐจ๋Ÿ‰ ๋ฒˆํ˜ธํŒ 1

by rlaehddnd0422

https://www.acmicpc.net/problem/16968

 

16968๋ฒˆ: ์ฐจ๋Ÿ‰ ๋ฒˆํ˜ธํŒ 1

00๋ถ€ํ„ฐ 99๊นŒ์ง€ ์ด 100๊ฐ€์ง€ ์ค‘์—์„œ 00, 11, 22, 33, 44, 55, 66, 77, 88, 99๊ฐ€ ๋ถˆ๊ฐ€๋Šฅํ•˜๋‹ค.

www.acmicpc.net

 

 

 

 

 

Solution 1

#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#define FASTio ios_base :: sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define endl '\n' 

using namespace std;

string s;

int main()
{
    FASTio;
    cin >> s;
    int a = 10;
    int b = 26;
    int sum = 1;

    for(int i=0;i<s.length();)
    {   
        if(s[i]=='d')
        {   
            int index = i+1;
            int ori = a-1;
            sum *= a;
            while(1)
            {
                if(s[index]!='d')
                {
                    i = index;
                    break;
                }
                else
                {   
                    sum *= ori;
                    index++;
                } 
            }

        }
        else if(s[i]=='c')
        {
            int index = i+1;
            int ori = b-1;
            sum *= b;
            while(1)
            {
                if(s[index]!='c')
                {
                    i = index;
                    break;
                }
                else
                {   
                    sum *= ori;
                    index++;
                } 
            }
        }
    }

    cout << sum;

    return 0;
}

 

์ˆซ์ž 0~9 ์ด 10๊ฐ€์ง€ ๊ฒฝ์šฐ์ด๊ณ ,

๋ฌธ์ž a~z  ์ด 26๊ฐ€์ง€ ๊ฒฝ์šฐ์ด๋‹ค.

 

ํ•˜์ง€๋งŒ, ๊ฐ™์€ ํ˜•์‹์ด ์—ฐ์†ํ•ด์„œ ๋‚˜์˜ค๋Š” ๊ฒฝ์šฐ ์ด ์ „์— ๋‚˜์˜จ ๋ฌธ์ž๋Š” ๋˜ ๋‚˜์˜ฌ ์ˆ˜ ์—†๋‹ค๋Š” ์กฐ๊ฑด์ด ์žˆ๋‹ค.

 

์˜ˆ๋ฅผ๋“ค์–ด dddc์˜ ๊ฒฝ์šฐ์—๋Š” 

 

์ฒซ๋ฒˆ์งธ ๋ฌธ์ž์— ๋‚˜์˜ฌ ์ˆ˜ ์žˆ๋Š” ๊ฒฝ์šฐ๋Š” 10๊ฐ€์ง€, ๋‘๋ฒˆ์งธ ๋ฌธ์ž์— ๋‚˜์˜ฌ ์ˆ˜ ์žˆ๋Š” ๊ฒฝ์šฐ๋Š” ์•ž์— ๋‚˜์˜จ ๋ฌธ์ž๋ฅผ ์ œ์™ธํ•œ 9๊ฐ€์ง€, ์„ธ๋ฒˆ์งธ ๋ฌธ์ œ์— ๋‚˜์˜ฌ ์ˆ˜ ์žˆ๋Š” ๊ฒฝ์šฐ๋Š” ๋‘๋ฒˆ์งธ ๋ฌธ์ž์— ๋‚˜์˜จ ๋ฌธ์ž๋ฅผ ์ œ์™ธํ•œ 9๊ฐ€์ง€,  ๋„ค๋ฒˆ์งธ ๋ฌธ์ž์— ๋‚˜์˜ฌ ์ˆ˜ ์žˆ๋Š” ๊ฒฝ์šฐ๋Š” 26๊ฐ€์ง€ 

 

์ด 10 * 9 * 9 * 26 ๊ฐ€์ง€์ด๋‹ค.

 

๋”ฐ๋ผ์„œ ๋ฌธ์ž๊ฐ€ ์—ฐ์†ํ•ด์„œ ๋‚˜์˜ค๋Š” ๊ฒฝ์šฐ์—๋Š” ์ˆซ์ž์ธ ๊ฒฝ์šฐ ์—ฐ์†ํ•ด์„œ ๋‚˜์˜ค์ง€ ์•Š์„๋•Œ๊นŒ์ง€ 9๋ฅผ ๊ณฑํ•ด์ฃผ์—ˆ๊ณ , ๋ฌธ์ž์˜ ๊ฒฝ์šฐ 25๋ฅผ ๊ณฑํ•ด ์ฃผ์—ˆ๋‹ค.

  

 

 

Solution 2 

#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#define FASTio ios_base :: sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define endl '\n' 
using namespace std;

string s;

int ans(int index, char before)
{   
    int sum = 0;

    if(s.length()==index)
    {
        return 1;
    }

    char start,end;

    if(s[index]=='c')
    {
        start = 'a';
        end = 'z';
    }
    else if (s[index]=='d')
    {
        start = '0';
        end = '9';
    }

    for(char c = start; c <= end ; c++)
    {
        if(c != before)
        {   
            sum += ans(index+1,c);
        }

    }

    return sum;
    

}
int main()
{
    FASTio;
    cin >> s;
    cout << ans(0,' ');
    return 0;
}

์ž…๋ ฅ๋ฐ›์€ ์ด์ „ ๋ฌธ์ž์™€ ๊ฐ™์€ ๊ฒฝ์šฐ๋ฅผ ์ œ์™ธํ•œ ๋ชจ๋“  ๊ฒฝ์šฐ๋ฅผ ์žฌ๊ท€์ ์œผ๋กœ ๊ตฌํ•ด์ฃผ์—ˆ๋‹ค.

 

 

 

 

'๐Ÿ“— CS > Algorithm' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

5014. ์Šคํƒ€ํŠธ๋งํฌ  (0) 2023.01.28
3187. ์–‘์น˜๊ธฐ ๊ฟ  (0) 2023.01.27
17089. ์„ธ ์นœ๊ตฌ  (0) 2023.01.24
15686. ์น˜ํ‚จ ๋ฐฐ๋‹ฌ  (0) 2023.01.23
17088. ๋“ฑ์ฐจ์ˆ˜์—ด ๋ฐ˜ํ™˜  (0) 2023.01.23

๋ธ”๋กœ๊ทธ์˜ ์ •๋ณด

Study Repository

rlaehddnd0422

ํ™œ๋™ํ•˜๊ธฐ