新东西 %[^\n]
这个题测试的时候不知道哪里为什么一直错一个。
int main()
{char a[81] = { 0 };fgets(a, 80, stdin);int i = 0;int n = strlen(a);for(i=0;i<n;i++){if ((a[i] >= 'a' && a[i] <= 'y') || (a[i] >= 'A' && a[i] <= 'Y'))a[i] += 1;else if (a[i] == 'z')a[i] = 'a';else if (a[i] == 'Z')a[i] = 'A';}puts(a);return 0;
}
这个题就提到了我上次提到的,对于这种周期性循环,可以用模求余的方式控制,
那个加21 实际上是-5+26,为了保证A~E的对应正确。
int main()
{char a[201] = { 0 };gets(a);int i = 0;int n = strlen(a);for (i = 0; i < n; i++){if(a[i]>='A'&&a[i]<='Z')a[i] = (a[i] - 'A' + 21) % 26 + 'A';}puts(a);return 0;
}
信息有点多,今天写的还是比较麻烦的,就是分别实现每个要求,然后最后打印
#include<string.h>int main()
{char a[101] = { 0 }, b[101] = { 0 }, c[101] = { 0 };scanf("%s %s %s", a, b, c);int na = strlen(a), nc = strlen(c);char d[26] = { 0 };int i = 0;for (i = 0; i < na; i++){for(int j=0;j<26;j++){if (b[i] == j + 'A'){d[j]++; break;}}}//第二个条件for(i=0;i<26;i++){if (d[i] == 0){printf("Failed\n"); return 0;}}char m = 0;for (i = 0; i < na; i++){int flag = 0;m = a[i];char x = 0;for (int j = 0; j < na; j++){if (a[j] == m && x != b[j]){x = b[j];flag++;}}if (flag > 1){printf("Failed\n"); return 0;}}for (i = 0; i < na; i++){int flag = 0;m = b[i];char x = 0;for (int j = 0; j < na; j++){if (b[j] == m && x != a[j]){x = a[j];flag++;}}if (flag > 1){printf("Failed\n"); return 0;}}for (i = 0; i < nc; i++){for (int j = 0; j < na; j++){if (c[i] == a[j]) {c[i] = b[j]; break;}}}puts(c);return 0;
}