第10课。
This commit is contained in:
32
10/Exercise01.c
Normal file
32
10/Exercise01.c
Normal file
@@ -0,0 +1,32 @@
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
|
||||
bool compareChar(char examinee, char pattern) {
|
||||
if(pattern == '?' || pattern == examinee) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
int index = 0, shift = 0;
|
||||
bool same = false;
|
||||
char sA[31] = {0}, sB[31] = {0};
|
||||
scanf("%s", sA);
|
||||
scanf("%s", sB);
|
||||
for (index = 0; index <= strlen(sA) - strlen(sB); index++) {
|
||||
same = true;
|
||||
for (shift = 0 ; shift < strlen(sB) && same; shift++) {
|
||||
if (!compareChar(sA[index+shift], sB[shift])) {
|
||||
same = false;
|
||||
}
|
||||
}
|
||||
if (same) {
|
||||
printf("%d ", index);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
25
10/Exercise02.c
Normal file
25
10/Exercise02.c
Normal file
@@ -0,0 +1,25 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
int main() {
|
||||
char vowels[100] = {0}, origin[1000] = {0};
|
||||
int vowelIndex = 0, originIndex = 0;
|
||||
scanf("%s", origin);
|
||||
for (originIndex = 0; originIndex < strlen(origin); originIndex++) {
|
||||
if (origin[originIndex] == 'a' || origin[originIndex] == 'e' || origin[originIndex] == 'i' || origin[originIndex] == 'o' ||origin[originIndex] == 'u') {
|
||||
vowels[vowelIndex] = origin[originIndex];
|
||||
vowelIndex++;
|
||||
}
|
||||
}
|
||||
|
||||
vowelIndex--;
|
||||
|
||||
for (originIndex = 0; originIndex < strlen(origin); originIndex++) {
|
||||
if (origin[originIndex] == 'a' || origin[originIndex] == 'e' || origin[originIndex] == 'i' || origin[originIndex] == 'o' ||origin[originIndex] == 'u') {
|
||||
origin[originIndex] = vowels[vowelIndex];
|
||||
vowelIndex--;
|
||||
}
|
||||
}
|
||||
printf("%s", origin);
|
||||
return 0;
|
||||
}
|
||||
25
10/Exercise03.c
Normal file
25
10/Exercise03.c
Normal file
@@ -0,0 +1,25 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
int main() {
|
||||
char inputString[100] = {0};
|
||||
int length = 0, i = 0;
|
||||
bool moved = true;
|
||||
char temp;
|
||||
scanf("%s", inputString);
|
||||
length = strlen(inputString);
|
||||
while (moved) {
|
||||
moved = false;
|
||||
for (int i = 0; i < length-1; i++) {
|
||||
if (inputString[i] < inputString[i+1]) {
|
||||
temp = inputString[i];
|
||||
inputString[i] = inputString[i+1];
|
||||
inputString[i+1] = temp;
|
||||
moved = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
printf("%s\n", inputString);
|
||||
return 0;
|
||||
}
|
||||
36
10/Optional01.c
Normal file
36
10/Optional01.c
Normal file
@@ -0,0 +1,36 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
int main() {
|
||||
char str[2][26] = {0};
|
||||
int count[2][26] = {0};
|
||||
int i = 0, length = 0;
|
||||
bool same = true;
|
||||
scanf("%s", str[0]);
|
||||
scanf("%s", str[1]);
|
||||
if (strlen(str[0]) != strlen(str[1])) {
|
||||
printf("0");
|
||||
}
|
||||
else {
|
||||
length = strlen(str[0]);
|
||||
for (i = 0; i < length; i++) {
|
||||
count[0][str[0][i]%26]++;
|
||||
count[1][str[1][i]%26]++;
|
||||
}
|
||||
for (i = 0; i < 26; i++) {
|
||||
if (count[0][i] != count[1][i]) {
|
||||
same = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (same) {
|
||||
printf("1");
|
||||
}
|
||||
else {
|
||||
printf("0");
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
10
10/Optional02.c
Normal file
10
10/Optional02.c
Normal file
@@ -0,0 +1,10 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
int aton(const char str[]) {
|
||||
|
||||
}
|
||||
|
||||
int main() {
|
||||
return 0;
|
||||
}
|
||||
17
10/test.c
Normal file
17
10/test.c
Normal file
@@ -0,0 +1,17 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
char c[10];
|
||||
static char b[10];
|
||||
int i = 0;
|
||||
scanf("%s", c);
|
||||
scanf("%s", b);
|
||||
for (i = 0; i < 10; i++) {
|
||||
printf("%c", c[i]);
|
||||
}
|
||||
printf("\n--------\n");
|
||||
printf("%s\n", b);
|
||||
printf("%s\n", c);
|
||||
printf("%c%c\n", 23, 49);
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user