백준 온라인 저지 채점 방법
(0) [BOJ 11654] 아스키 코드
| //code by RiKang, weeklyps.com #include <stdio.h> int main(void) { char c; scanf("%c",&c); printf("%d",c); return 0; } | cs |
(1) [BOJ 11721] 열 개씩 끊어 출력하기
| //code by RiKang, weeklyps.com #include <stdio.h> #include <string.h> int main(void) { char c[105]; scanf("%s",c); int n = strlen(c); for(int i=0; i<n; i++){ printf("%c",c[i]); if(i%10==9) printf("\n"); } return 0; } | cs |
(2) [BOJ 10808] 알파벳 개수
| //code by RiKang, weeklyps.com #include <stdio.h> #include <string.h> int main(void) { char c[105]; int cnt[305]={0,}; scanf("%s",c); int n = strlen(c); for(int i=0; i<n; i++){ cnt[c[i]]++; // 문자를 아스키 코드값으로 활용 } for(int i='a'; i<='z'; i++) // 문자를 아스키 코드값으로 활용 printf("%d ",cnt[i]); return 0; } | cs |
(3) [BOJ 10987] 모음의 개수
| //code by RiKang, weeklyps.com #include <stdio.h> #include <string.h> int main(void) { char c[105]; int cnt=0; scanf("%s",c); int n = strlen(c); for(int i=0; i<n; i++){ if(c[i]=='a' || c[i]=='e' || c[i]=='i' || c[i]=='o' || c[i]=='u') cnt++; } printf("%d",cnt); return 0; } | cs |
(4) [BOJ 1157] 단어 공부
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 | //code by RiKang, weeklyps.com #include <stdio.h> #include <string.h> int main(void) { char c[1000005]; int cnt[305]={0,}; scanf("%s",c); int n = strlen(c); for(int i=0; i<n; i++){ if(c[i]>='a' && c[i]<='z'){ // 아스키 코드값을 활용해 소문자->대문자 변환 c[i]-='a'; c[i]+='A'; } cnt[c[i]]++; } int max_cnt=0; char ans; for(int i='A'; i<='Z'; i++){ if(max_cnt<cnt[i]){ // max_cnt = 가장 많이 사용된 알파벳이 사용된 횟수 max_cnt = cnt[i]; ans=i; } else if(max_cnt==cnt[i]) ans='?'; // max_cnt만큼 사용된 알파벳이 여러 개인 경우 } printf("%c",ans); return 0; } | cs |
(5) [BOJ 8958] OX퀴즈
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | //code by RiKang, weeklyps.com #include <stdio.h> #include <string.h> int main(void) { char c[105]; int t; scanf("%d",&t); for(int i=1; i<=t; i++){ scanf("%s",c); int n = strlen(c); int score = 0, sum=0; for(int j=0; j<n; j++){ if(c[j]=='O'){ score++; sum+=score; } else score=0; } printf("%d\n",sum); } return 0; } | cs |
(6) [BOJ 2675] 문자열 반복
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | //code by RiKang, weeklyps.com #include <stdio.h> #include <string.h> int main(void) { char c[105]; int t; scanf("%d",&t); for(int i=1; i<=t; i++){ int m; scanf("%d %s",&m,c); int n = strlen(c); for(int j=0; j<n; j++) for(int k=0; k<m; k++) printf("%c",c[j]); printf("\n"); } return 0; } | cs |
(7) [BOJ 10173] 니모를 찾아서
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 | //code by RiKang, weeklyps.com #include <stdio.h> #include <string.h> int main(void) { char c[105]; char nemo[5]="NEMO"; while(1){ int ans=0; gets(c); int n = strlen(c); if(n==3 && c[0]=='E' && c[1]=='O' && c[2]=='I') break; // EOI 가 들어왔으므로 while 문을 종료시킨다. for(int i=0; i<n; i++){ if(c[i]>='a' && c[i]<='z'){ // 아스키 코드값을 활용해 소문자->대문자 변환 c[i]-='a'; c[i]+='A'; } } for(int i=0; i+3<n; i++){ int is_ans=1; for(int j=0; j<4; j++){ // c[i] ~ c[i+3] 이 NEMO 인지 판별한다. if(c[i+j]!=nemo[j]) // is_ans = 0 인 상태로 끝나면 NEMO가 아니다. is_ans=0; // is_ans = 1 인 상태로 끝나면 NEMO이다. } if(is_ans) ans = 1; // NEMO 를 찾았다. } if(ans==0) printf("Missing\n"); else printf("Found\n"); } return 0; } | cs |
(8) [BOJ 10798] 세로읽기
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | //code by RiKang, weeklyps.com #include <stdio.h> #include <string.h> int main(void) { char c[5][20]; int n[5]; for(int i=0; i<5; i++){ scanf("%s",c[i]); // 2차원 배열이므로, c[i] 가 곧 i 번째 문자열의 이름이자 주소이다. n[i] = strlen(c[i]); } for(int i=0; i<15; i++){ for(int j=0; j<5; j++){ // j 번째 문자열의 i 번째 값을 출력한다. if(n[j] > i) // n[j]<=i 인 경우는 출력할 것이 없다. printf("%c",c[j][i]); } } return 0; } | cs |
(9) [BOJ 11655] ROT13
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | //code by RiKang, weeklyps.com #include <stdio.h> #include <string.h> int main(void) { char c[105]; gets(c); int n = strlen(c); for(int i=0; i<n; i++){ if(c[i]>='a' && c[i]<='z'){ c[i]-=13; if(c[i]<'a') c[i]+=26; } if(c[i]>='A' && c[i]<='Z'){ c[i]-=13; if(c[i]<'A') c[i]+=26; } } printf("%s",c); return 0; } | cs |