zoukankan      html  css  js  c++  java
  • UVA

    //程序3-7 回文词
    //收获:
    //1、回文串和镜像串的判定(尤其镜像串,借用了一个常量数组)同时,用到了函数
    //2、同时,这题的循环控制条件是有值得推敲之处,因为镜像串即便只剩下一个元素,还需要判定它的字符镜像是否是它本身
    //3、此外,这题的结果输出,也是用了字符串数组,并且用到了2个变量jud1和jud2,利用两者的运算,成功地表示了所有的4种情况,十分巧妙 


    #include <iostream>
    #include <cstring>
    #include <cctype>
    using namespace std;
    const char* a = "A   3  HIL JM O   2TUVWXY51SE Z  8 ";
    const char* mes[4] = {"is not a palindrome.", "is a regular palindrome.", "is a mirrored string.", "is a mirrored palindrome."};
    char r(char ch)
    {
    	if (isalpha(ch))
    	return a[ch - 'A'];
    	return a[25 + ch - '0'];
    }
    int main()
    {
    	char s[20];
    	int jud1, jud2, len, i;
    	while (cin >> s)
    	{
    		len = strlen(s);
    		jud1 = jud2 = 1;//最开始,先当作又是回文数,又是镜像数
    		for (i = 0; i < (len + 1) / 2; i++)
    		{
    			if (s[i] != s[len - 1 - i]) jud1 = 0;
    			if (r(s[i]) != s[len - 1- i]) jud2 = 0;
    		}
    		cout << s << " -- " << mes[2 * jud2 + jud1] << endl << endl;
    	}
    		return 0;
    }


  • 相关阅读:
    如何安装树莓派虚拟机
    树莓派3用create_ap变身无线AP
    Centos 安装golang beego
    Lua中调用C函数
    C++ 用libcurl库进行http通讯网络编程(转)
    SkipList 跳表
    ntohs, ntohl, htons,htonl的比较和详解【转】
    SQLITE3 使用总结(转)
    mysql基础认识1
    mysql 数据类型
  • 原文地址:https://www.cnblogs.com/mofushaohua/p/7789466.html
Copyright © 2011-2022 走看看