OAIP/21-22/21.c

110 lines
1.6 KiB
C
Raw Normal View History

#include "stdio.h"
#include "Windows.h"
int isDigit(char);
char toUpperCase(char);
int main1() {
SetConsoleCP(1251);
SetConsoleOutputCP(1251);
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: ");
char ch = ' ';
scanf_s("%c", &ch);
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 1\n");
for (int i = ch; i <= ch + 19; i++) {
printf("%c, %d\n", i, i);
}
printf("\n<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 2\n");
for (int i = ch; i >= ch - 29; i--) {
printf("%c, %d\n", i, i);
}
printf("\n<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 3\n");
char str[100];
int k = 0;
scanf_s(" %[^\n]", &str, 100);
printf("%s\n", str);
for (int i = 0; i < strlen(str); i++)
if (str[i] == ' ') k++;
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> = %d\n", k);
printf("\n<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 4\n");
scanf_s(" %[^\n]", &str, 100);
printf("%s\n", str);
for (int i = 0; i < strlen(str); i++)
if (str[i] == ' ') str[i] = '#';
printf("%s\n", str);
printf("\n<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 5\n");
scanf_s(" %[^\n]", &str, 100);
printf("%s\n", str);
for (int i = 0; i < strlen(str); i++)
if (isDigit(str[i])) str[i] = '$';
printf("%s\n", str);
printf("\n<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 6\n");
scanf_s(" %[^\n]", &str, 100);
printf("%s\n", str);
for (int i = 0; i < strlen(str); i++)
str[i] = toUpperCase(str[i]);
printf("%s\n", str);
printf("\n<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 9 <20>8\n");
scanf_s(" %[^\n]", &str, 100);
printf("%s\n", str);
for (int i = 0; i < strlen(str); i++)
if(!(str[i] >= 'a' && str[i] <= 'z' || str[i] >= 'A' && str[i] <= 'Z'))
str[i] = '_';
printf("%s\n", str);
return 0;
}
int isDigit(char c) {
return c > '0' && c <= '9';
}
char toUpperCase(char c) {
if (c >= 'a' && c <= 'z') return 'A' + (c - 'a');
if (c == '<EFBFBD>') return '<EFBFBD>';
return c;
}