SWEA 1926 간단한 369게임

1 개요[ | ]

SWEA 1926 간단한 369게임

2 C++[ | ]

.
#include <iostream>
using namespace std;
int N;
int count369(int n) {
	int count = 0;
	while(true) {
		int digit = n % 10;
		if( digit==3 || digit==6 || digit==9 ) count++;
		n /= 10;
		if( n == 0 )break;
	}
	return count;
}
int main() {
	scanf("%d", &N);
	for(int i=1; i<=N; i++) {
		int count = count369(i);
		if( count == 0 ) {
			printf("%d ", i);
			continue;
		}
		for(int j=0; j<count; j++) {
			printf("-");
		}
		printf(" ");
	}
}

3 Java[ | ]

import java.util.Scanner;
import java.util.regex.*;
class Solution {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        Pattern pattern = Pattern.compile("[369]");
        String dashes;
        Matcher matcher; 
        for(int i=1; i<=N; i++) {
            matcher = pattern.matcher( String.valueOf(i) );
            dashes = "";
            while( matcher.find() ) dashes += "-";
            if( dashes.equals("") ) System.out.format( "%d ", i );
            else System.out.format( "%s ", dashes  );
        }
    }
}

4 Python[ | ]

#kcy
k = int(input())
cnt = 0
for i in range(1, k+1):
    j = str(i)
    if i < 10:
        if j in ['3', '6', '9']:
            cnt = cnt + 1     
    elif (i >= 10 and i < 100):
        for y in range(0, 2):
            if (j[y:y+1] in ['3', '6', '9']):
                cnt = cnt + 1
    else:
        for y in range(0, 3):
            if (j[y:y+1] in ['3', '6', '9']):
                cnt = cnt + 1
    if cnt > 0:
        print('-'*cnt, end = ' ')
    else:
        print(i, end = ' ')
    cnt = 0
T = int(input())
for i in range(1, T+1):
    s = sum(1 for x in str(i) if x in ['3','6','9'])
    if s==0:
        print( i, end=' ' )
    else:
        print( '-'*s, end=' ' )
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}