이것저것
정올 - 문자열1 본문
http://www.jungol.co.kr/bbs/board.php?bo_table=pbank&sca=10e0
JUNGOL
www.jungol.co.kr
자가진단1
#include <stdio.h>
int main(void) {
int n;
while (1) {
printf("ASCII code =? ");
scanf("%d", &n);
if ((65 <= n && n <= 90) || (97 <= n && n <= 122)) {
printf("%c\n", n);
}
else return;
}
return 0;
}
자가진단2
#include <stdio.h>
int main(void) {
char s1[10];
scanf("%s", s1);
for (int i = 0; i < 2; i++)
printf("%s", s1);
return 0;
}
자가진단3
#include <stdio.h>
int main(void) {
char s1[] = "Hong Gil Dong";
for (int i = 3; i <= 6; i++)
printf("%c", s1[i]);
return 0;
}
자가진단4
#include <stdio.h>
#include <string.h>
int main(void) {
char s[100];
int n;
scanf("%s %d", s, &n);
for(int i = strlen(s)-1; i>= strlen(s) -3; i--)
printf("%c", s[i]);
return 0;
}
자가진단5
#include <stdio.h>
#include <string.h>
int main(void) {
char s1[20], s2[20];
scanf("%s %s", s1, s2);
printf("%d", strlen(s1) + strlen(s2));
return 0;
}
자가진단6
#include <stdio.h>
int main(void) {
char c;
while (1) {
scanf(" %c", &c);
if ((65 <= c && c <= 90) || (97 <= c && c <= 122))
printf("%c\n", c);
else if (48 <= c && c <= 57)
printf("%d\n", c);
else
return;
}
return 0;
}
자가진단7
#include <stdio.h>
#include <string.h>
int main(void) {
char s[100];
scanf("%s", s);
for (int i = 0; i < strlen(s); i++) {
if (65 <= s[i] && s[i] <= 90)
printf("%c", s[i]);
if (97 <= s[i] && s[i] <= 122)
printf("%c", s[i] - 'a' + 65);
}
return 0;
}
자가진단8
#include <stdio.h>
#include <string.h>
int main(void) {
char str[100];
int n = 1;
fgets(str, 100, stdin);
for (int i = 0; i < strlen(str); i++) {
if (str[i] == ' ')
n++;
}
printf("%d", n);
return 0;
}
자가진단9
#include <stdio.h>
#include <string.h>
int main(void) {
char str[100], c;
scanf("%s", str);
for (int i = 0; i < strlen(str); i++) {
c = str[strlen(str) - 1]; // 마지막 인덱스
for (int j = strlen(str) - 1; j >= 0; j--)
str[j] = str[j - 1]; // 옆으로 이동
str[0] = c; // 첫번재 인덱스에 이전 마지막 인덱스에 존재하던 문자 넣기
printf("%s\n", str);
}
return 0;
}
형성평가1
#include <stdio.h>
int main(void) {
char a, b;
scanf("%c %c", &a, &b);
printf("%d %d", a + b, b-a);
return 0;
}
형성평가2
#include <stdio.h>
int main(void) {
char str[100];
scanf("%s", str);
for (int i = 0; i < 5; i++)
printf("%c", str[i]);
return 0;
}
형성평가3
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int main(void) {
char str[100];
scanf("%s", str);
for (int i = 0; i < strlen(str); i++) {
if (48 <= str[i] && str[i] <= 57)
printf("%c", str[i]);
if (65 <= str[i] && str[i] <= 90)
printf("%c", tolower(str[i]));
if (97 <= str[i] && str[i] <= 122)
printf("%c", str[i]);
}
return 0;
}
형성평가4
#include <stdio.h>
#include <string.h>
int main(void) {
char str[100], c;
scanf("%s %c", str, &c);
for (int i = 0; i < strlen(str); i++) {
if (str[i] == c) {
printf("%d", i);
return;
}
}
printf("NO");
}
형성평가5
#include <stdio.h>
#include <string.h>
int main(void) {
char str1[100], str2[100];
scanf("%s %s", str1, str2);
strlen(str1) > strlen(str2) ? printf("%d", strlen(str1)) : printf("%d", strlen(str2));
return 0;
}
형성평가6
#include <stdio.h>
int main(void) {
char str[100];
int c;
scanf("%s", str);
while (1) {
scanf("%d", &c);
// 입력받은 숫자가 문자열 길이 이상인 경우
if (c >= strlen(str)) {
str[strlen(str) - 1] = '\0';
printf("%s\n", str);
// 남은 문자 1개인 경우
if (strlen(str) == 1)
break;
else
continue;
}
// 문자열 재배치
for (int i = c; i < strlen(str); i++) {
str[i - 1] = str[i];
}
str[strlen(str)-1] = '\0';
printf("%s\n", str);
// 남은 문자 1개인 경우
if (strlen(str) == 1)
break;
}
return 0;
}
형성평가7
#include <stdio.h>
#include <string.h>
int main(void) {
char str[100];
int a= 1, num = 0;
fgets(str, 100, stdin);
for (int i = 0; i < strlen(str); i++) {
if (str[i] == ' ') { // 공백 나타나면
printf("%d. ", a++);
for (int j = num; j < i; j++)
printf("%c", str[j]); // 출력
printf("\n");
num = i + 1; // 다음 단어 첫번째 위치로 이동
}
}
// 마지막 단어
printf("%d. ", a);
for (int j = num; j < strlen(str); j++)
printf("%c", str[j]);
return 0;
}