摘要: C++作用域运算符::主要有2种应用方式。其一,声明一个类A,类A里声明了一个成员函数void f(),但没有在类的声明里给出f的定义,那么在类外定义f时,就要写成void A::f(),表示这个f()函数是类A的成员函数。其二,作用域可以简单分为:全局作用域,局部作用域,语句作用域作用域优先级:范围越小优先级越高作用域运算符:"::"如果希望在局部变量的作用域内使用同名的全局变量,可以在该变量前加上"::","::"称为作用域运算符.eg://作用域#include <iostream>using namespace s 阅读全文
posted @ 2013-04-13 21:10 Emma437211 阅读(3976) 评论(0) 推荐(0) 编辑
摘要: 在学习了前面python课程的综合知识后,再来做个小游戏。游戏规则:任给一个文件file,实现一个dict,key为file中出现的单词,value为一个由key在file中出现的位置后紧跟的下一个单词组成的list。例如:file中,紧跟单词'and'后可能出现了'then','the','you'等,则dict中包含{'and',['then','the','you']}。详细描述如下:"""Mimic pyquick exercis 阅读全文
posted @ 2013-04-03 10:46 Emma437211 阅读(1222) 评论(0) 推荐(0) 编辑
摘要: 在学习了python的基本数据类型及相关语法后,现综合所学list,tuples,str,dict,sort,file等知识,解决以下问题。题目及代码如下: 1 # -*- coding: cp936 -*- 2 """ 3 1. For the --count flag, implement a print_words(filename) function that counts 4 how often each word appears in the text and prints: 5 word1 count1 6 word2 count2 7 ... 8 阅读全文
posted @ 2013-04-02 17:14 Emma437211 阅读(553) 评论(0) 推荐(0) 编辑
摘要: list2里面含两个练习,方法多彩多样。D题实现对list内数据去重操作,E题实现对已排序list实现归并排序,并且要求线性时间复杂度。题目和代码如下: 1 # D. Given a list of numbers, return a list where 2 # all adjacent == elements have been reduced to a single element, 3 # so [1, 2, 2, 3] returns [1, 2, 3]. You may create a new list or 4 # modify the passed in list. 5 de 阅读全文
posted @ 2013-04-01 18:41 Emma437211 阅读(297) 评论(0) 推荐(0) 编辑
摘要: 学习完string之后,现在来看看list的用法: 1 # -*- coding: cp936 -*- 2 #A. match_ends 3 # Given a list of strings, return the count of the number of 4 # strings where the string length is 2 or more and the first 5 # and last chars of the string are the same. 6 def match_ends(words): 7 count = 0 8 for item in... 阅读全文
posted @ 2013-03-30 18:03 Emma437211 阅读(368) 评论(0) 推荐(0) 编辑