如何获取数组第一个元素的镜像?

问题描述

我需要将数字输入到一个数组中,获取第一个数字,对其进行镜像,然后查看该数组中的其他数字是否与镜像相同。

示例:4 个数字,123 321 111 和 200; 123 的镜像是 321,所以它应该告诉我“是”,因为数组中还有 1 个元素与镜像相同。

#include <iostream>
    
using namespace std;
    
int main()
{
    int n = 0,mirror,cnt = 0;
    int* v = new int[n];
    
    cout << "How many elements?\n";
    cin >> n;
    
    for(int i=0; i<n; i++)
        cin >> v[i];
    
    while(v[0] != 0){
        mirror = mirror * 10 + v[0] % 10;
        v[0] /= 10;
    }
    cout << mirror;
    for(int i=0; i<n; i++)
        if(v[i] == mirror && v[i] != v[0])
            cnt++;
    if(cnt >=1)
        cout << "Yes";
    else
        cout << "No";
    return 0;
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)