"SWEA 16910 원 안의 점"의 두 판 사이의 차이

1번째 줄: 1번째 줄:
==개요==
==개요==
{{SWEA|난이도=3}}
{{SWEA|난이도=3}}
==C==
<syntaxhighlight lang='c'>
#include<stdio.h>
   
int countPoint(int n) {
    int x, y;
    int count = 0;
    for(x=1; x<=n; x++) {
        for(y=1; y<=n; y++) {
            if(x*x + y*y <= n*n) {
                count++;
            }
        }
    }
    return 4*count + 4*n + 1;
}
       
int main( ) {
int T, N;
    scanf("%d", &T);
    for(int testcase=1; testcase<=T; testcase++) {
    scanf("%d", &N);
        printf("#%d %d\n", testcase, countPoint(N));
    }
}
</syntaxhighlight>


==C++==
==C++==

2023년 8월 26일 (토) 03:26 판

1 개요

SWEA 16910 원 안의 점

2 C

#include<stdio.h>
    
int countPoint(int n) {
    int x, y;
    int count = 0;
    for(x=1; x<=n; x++) {
        for(y=1; y<=n; y++) {
            if(x*x + y*y <= n*n) {
                count++;
            }
        }
    }
    return 4*count + 4*n + 1;
}
        
int main( ) {
	int T, N;
    scanf("%d", &T);
    for(int testcase=1; testcase<=T; testcase++) {
	    scanf("%d", &N);
        printf("#%d %d\n", testcase, countPoint(N));
    }
}

3 C++

#include <cstdio>
using namespace std;
    
int countPoint(int n) {
    int x, y;
    int count = 0;
    for(x=1; x<=n; x++) {
        for(y=1; y<=n; y++) {
            if(x*x + y*y <= n*n) {
                count++;
            }
        }
    }
    return 4*count + 4*n + 1;
}
        
int main( ) {
	int T, N;
    scanf("%d", &T);
    for(int testcase=1; testcase<=T; testcase++) {
	    scanf("%d", &N);
        printf("#%d %d\n", testcase, countPoint(N));
    }
}
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}