不会的题目

1133~1137都有问题

#include <iostream>
#include <string>
#include <map>

using namespace std;

// 定义镜像字符映射表
map<char, char> mirror = {
    {'A', 'A'}, {'M', 'M'}, {'Y', 'Y'}, {'Z', '5'}, {'O', 'O'}, {'1', '1'}, {'2', 'S'}, {'E', '3'}, {'3', 'E'},
    {'S', '2'}, {'5', 'Z'}, {'H', 'H'}, {'T', 'T'}, {'I', 'I'}, {'U', 'U'}, {'J', 'L'}, {'V', 'V'}, {'8', '8'},
    {'W', 'W'}, {'L', 'J'}, {'X', 'X'}
};

int main() {
    string s;
    while (getline(cin, s)) {  // 读取整行输入
        int h = 1;  // 是否是回文
        int m = 1;  // 是否是镜像字符串
        int len = s.length();

        // **检查是否是回文**
        for (int i = 0; i < len / 2; i++) {
            if (s[i] != s[len - i - 1]) {
                h = 0;  // 不是回文
                break;
            }
        }

        // **检查是否是镜像字符串**
        for (int i = 0; i <(len +1)/ 2; i++) {  // 遍历整个字符串
            if (mirror.find(s[i]) == mirror.end() || mirror.find(s[len - i - 1]) == mirror.end()) {
                m = 0;
                break;
            }
        }

        // **格式化输出**
        cout << s << " -- ";
        if (h == 1 && m == 1) {
            cout << "is a mirrored palindrome.";
        } else if (h == 1) {
            cout << "is a regular palindrome.";
        } else if (m == 1) {
            cout << "is a mirrored string.";
        } else {
            cout << "is not a palindrome.";
        }
        cout << endl << endl;  // 题目要求,每个输出后需要空行
    }
    return 0;
}

最后测试数据:2A3MEAS不对,感觉疑似镜像那个条件判断不太对

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(){
    char s[30],e[30];
    scanf("%s",s);
    scanf("%s",e);
    int len=strlen(s);
    char c;
    printf("%s\n",e);
    printf("%s\n",s);
    while(scanf("%c",&c)!=EOF){
        for(int i=0;i<len;i++){
            if(s[i]==c){
                c=e[i];
            }
        }
        printf("%c",c);
    }


}



#include <iostream>
using namespace std;
#include <string>
int main()
{
      int n;
      int r;
      string str;
      int len=0;
      int flag=1;//默认是
      int first=1;
      while(cin>>n){
            if(n==0)
             break;
            int temp;
            first=1;
            printf("Number %d is ",n);
            for(r=2;r<17;r++){
                    flag=1;
                    temp=n;
                    len=0;
                while(temp){
                    str[len++]=(temp%r<10)?temp%r+'0':temp%r-10+'A';
                    temp=temp/r;
                }
                for(int i=0;i<len/2;i++){
                    if(str[i]!=str[len-i-1]){
                        flag=0;
                        break;
                    }
                }

                if(flag==1){
                        if(first==1){
                            printf("palindrom in basis %d",r);
                            first=0;
                        }
                        else{
                             printf("% d",r);
                        }

                }
            }
             if(flag==0){
                    printf("is not a palindrom");
                }
            printf("\n");



      }

}

第三页这两也不会

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值