题目:输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数。def foo(a): l=len(a); letters=0; space=0; digit=0; others=0; for i in range(0,l): num=ord...
分类:
编程语言 时间:
2014-09-13 09:22:44
阅读次数:
228
题目:输入两个正整数m和n,求其最大公约数和最小公倍数。def foo(a,b): if a<b: (a,b)=(b,a) aa=a; bb=b; while b!=0: tmp=a%b; a=b; b=tmp; ...
分类:
编程语言 时间:
2014-09-13 09:21:14
阅读次数:
198
三点以下的情况就不写了
Python:
import math
class Point( object ):
def __init__( self, x, y ):
self.x = x
self.y = y
def __cmp__( self, other ):
if self.y < other.y:...
分类:
其他好文 时间:
2014-09-13 00:50:24
阅读次数:
409
题目:利用条件运算符的嵌套来完成此题:学习成绩〉=90分的同学用A表示,60-89分之间的用B表示,60分以下的用C表示。def foo(n): if n>=90: print 'A' , elif n>=60: print 'B' , else: ...
分类:
编程语言 时间:
2014-09-12 21:57:14
阅读次数:
286
题目:将一个正整数分解质因数。例如:输入90,打印出90=2*3*3*5。def foo(n): while 1: for i in range(2,n+1): if n%i==0: print i, ...
分类:
编程语言 时间:
2014-09-12 21:54:14
阅读次数:
319
又遇到一个有意思的问题,它提醒了查阅文档和相关源码,与测试的重要性。
直接上代码,setup.py
"""
module: setup
"""
from lib import *
from config import *
form, base = loadUiType("setup.ui")
class SetupDlg(QDialog, form):
def __init__(s...
分类:
其他好文 时间:
2014-09-12 20:48:04
阅读次数:
289
线段树的模板题,还是二分递归。
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
typedef long long LL;
#define MAXD 10
#def...
分类:
其他好文 时间:
2014-09-12 20:44:04
阅读次数:
222
若列表中某元素存在则返回之任务: 你有一个列表L,还有一个索引号i,若i是有效索引时,返回L[i],若不是,则返回默认值v 解决方案:列表支持双向索引,所以i可以为负数>>> def list_get(L,i,v=None): if -len(L)>> list_get([1,2,3,4,...
分类:
编程语言 时间:
2014-09-12 17:05:03
阅读次数:
238
题目:输入三个整数x,y,z,请把这三个数由小到大输出。def swap(a,b): t=a; a=b; b=t; return (a,b);def foo(x,y,z): if x>y: (x,y)=swap(x,y) if x>z: ...
分类:
编程语言 时间:
2014-09-12 17:03:33
阅读次数:
195
举个例子:import csvimport ospath='/tmp/'file='test.csv'def generate_csv(path,file): if not os.path.exists(path): os.mkdir(path) files=os.path...
分类:
编程语言 时间:
2014-09-12 16:51:53
阅读次数:
235