2014年7月25日
摘要: 1. 词法“陷阱”= 不同于 == , 可以通过if( 1 == a )来避免& | 不同于 && ||词法分析中的“贪心法”编译器将程序分解成符号的方法是,从左到右一个字符一个字符地读入,如果该字符可能组成一个符号,那么再读入下一个字符,判断已经读入的两个字符组成的字符串是否可能是一个符号的组成部... 阅读全文
posted @ 2014-07-25 12:17 DayByDay 阅读(379) 评论(0) 推荐(0) 编辑
  2014年7月24日
摘要: 题目:输入一个整数,输出该数二进制表示中1的个数。// 二进制中1的个数#include int wrong_count_1_bits(int n) // 错误解法: 当n为负数时, n>>=1右移, 最高位补1, 陷入死循环{ int count = 0; while(n) { ... 阅读全文
posted @ 2014-07-24 19:45 DayByDay 阅读(305) 评论(0) 推荐(0) 编辑
摘要: // 判断两个单词是否互为变位词: 如果两个单词中的字母相同,并且每个字母出现的次数也相同, 那么这两个单词互为变位词#include #include int is_anagram(char *s1, char *s2) // 判断两个数是否互为变位词, 若是返回1{ if(strlen(s... 阅读全文
posted @ 2014-07-24 01:39 DayByDay 阅读(292) 评论(0) 推荐(0) 编辑
摘要: // 从第一个字符串中删除第二个字符串中出现过的所有字符#include char* remove_second_from_first( char *first, char *second ){ if( first == NULL || second == NULL ) { ... 阅读全文
posted @ 2014-07-24 01:18 DayByDay 阅读(686) 评论(0) 推荐(0) 编辑
摘要: 题目:在字符串中找出第一个只出现一次的字符。如输入"abaccdeff",这输出'b'// 第一个只出现一次的字符#include char first_not_repeat_char(char *s){ int count[256]={0}; char *pkey; if( s=... 阅读全文
posted @ 2014-07-24 01:01 DayByDay 阅读(218) 评论(0) 推荐(0) 编辑
摘要: /* * 动态分配存储的顺序表 */#include #include #define INIT_SIZE 100#define EXPAND_SIZE 50typedef int ElemType;typedef struct { ElemType *head; int len; //... 阅读全文
posted @ 2014-07-24 00:31 DayByDay 阅读(1228) 评论(0) 推荐(0) 编辑
  2014年7月23日
摘要: 题目:输入数值n,按顺序打印从1到最大的n位数,例如输入n=3,则从1,2,3,一直打印到999陷阱:若使用循环遍历 1- 999...9 并依次输出,当位数n过大时,无论将其存入int或long或long long都会溢出,故使用字符串来模拟数字加法#include #include #inclu... 阅读全文
posted @ 2014-07-23 23:29 DayByDay 阅读(332) 评论(0) 推荐(0) 编辑
  2014年7月18日
摘要: 题目:应用递归,将输入的二进制数转换为十进制。#include #include void binary_to_decimal(char *s, long dec){ if( *s == '\0' ) printf("Decimal: %ld\n",dec); else ... 阅读全文
posted @ 2014-07-18 14:05 DayByDay 阅读(1104) 评论(0) 推荐(0) 编辑
摘要: 题目:如果整数A的全部因子(包括1,不包括A本身)之和等于B,并且整数B的全部因子(包括1,不包括B本身)之和等于A,,则称整数A和B为亲密数。求解3000以内的全部亲密数。#include #include int factor_sum(int n) // 计算n的因子和{ int i; ... 阅读全文
posted @ 2014-07-18 13:36 DayByDay 阅读(574) 评论(0) 推荐(0) 编辑