2010年12月31日
摘要: 类似二进制的转换,10120(skew) = 1 * (2^5-1) + 0 * (2^4-1) + 1 * (2^3-1) + 2 * (2^2-1) + 0 * (2^1-1) code:#include iostream#include cstdio#include cstdlib#include cstringusing namespace std;char str[20];int main(){ int sum, k, t; while(scanf("%s", str)) { if(str[0]=='0') break; sum=0; k=1; int m=strle 阅读全文
posted @ 2010-12-31 23:16 FreeAquar 阅读(164) 评论(0) 推荐(0) 编辑
摘要: 筛法求素数code:#include iostream#include cstdio#include cstdlib#include cstring#define MAXN 35000using namespace std;bool prime[MAXN];void is_prime(){ int i, j; for(i=2; iMAXN; i++) { if(prime[i]==0) for(j=i+i; jMAXN; j+=i) prime[j]=1; }}int main(){ memset(prime, 0, sizeof(prime)); is_prime(); 阅读全文
posted @ 2010-12-31 22:16 FreeAquar 阅读(114) 评论(0) 推荐(0) 编辑
摘要: 计算ip地址code:#include iostream#include cstdio#include cstdlib#include cstringusing namespace std;int bit[8]={128, 64, 32, 16, 8, 4, 2, 1};int main(){ int n, sum, i; char str[35]; while(scanf("%d", &n)!= EOF) { while(n--) { scanf("%s", str); sum=0; for(i=0; i32; i++) { if(str[i]=='1') sum+=bit 阅读全文
posted @ 2010-12-31 15:23 FreeAquar 阅读(169) 评论(0) 推荐(0) 编辑
摘要: 练习输出code:#include iostream#include cstdio#include cstdlibusing namespace std;int factorial(int a){ if(a!=0 && a!=1) return a*factorial(a-1); else return 1;}int main(){ printf("n e\n- -----------\n"); double sum(0); for(int i=0; i10; i++) { printf("%d %.10g\n", i,sum+=1.0/factorial(i)); } retu 阅读全文
posted @ 2010-12-31 14:51 FreeAquar 阅读(134) 评论(0) 推荐(0) 编辑