- 博客(52)
- 资源 (1)
- 收藏
- 关注
原创 排序与检索6174问题
int get_next(int x){ int a,b,n; char s[10]; sprintf(s,"%d",x);//化为字符串 n=strlen(s); for(int i=0;i<n;i++)//冒泡排序 { for(int j=i+1;j<n;j++) { if(s[i]>s[j]) { char t=s[i]; s[i]=s[j]
2014-11-30 21:58:12 326
原创 冒泡排序
在要排序的一组数中,对当前还未排好序的范围内的全部数,自上而下对相邻的两个数依次进行比较和调整,让较大的数往下沉,较小的往上冒。即:每当两相邻的数比较后发现它们的排序与排序要求相反时,就将它们互换。稳定O(n2)for(int i=0;i<n;i++){ for(int j=i+1;j<n;j++){ if(s[i]>s[j]){ char t=s[i]; s[i]=s[
2014-11-30 21:39:36 249
原创 bign的结合有问题无法运行
#include iostream#include #include using namespace std;const int maxn=200;struct bign{ bign(){ int len,s[maxn]; memset(s,0,sizeof(s)); len=1; }bign(int num){ *this=num;}bign(char *nu
2014-11-30 21:14:57 353
原创 bool
1、类型不同bool为布尔型用作逻辑判断BOOL在typedef int BOOL;在typedef long BOOL;2、长度不同bool只有一个字节BOOL长度视实际环境来定,一般可认为是4个字节3、取值不同bool取值false和true,是0和1的区别; false可以代表0,但true有很多种,并非只有1。
2014-11-30 19:21:41 667
原创 设计一个结构体bign来存贮高精度非负整数
const int maxn=3000;struct bign{ int len,s[maxn]; bign(){memset(s,0,sizeof(s));len=1;}};上面的结构体中有一个函数,称为构造函数,它是c++中特有的,作用是进行初始化。事实上,当定义bign X时候,就会执行这个函数,把x.s清零,并赋值x.len=1;需要注意的是在c++中,并不需要typed
2014-11-30 15:18:25 827
原创 阶乘的精确值
#include #include const int maxn=3000;int f[maxn];int main(void){ int i,j,n; scanf("%d",&n); memset(f,0,sizeof(f)); f[0]=1; for(i=2;i<=n;i++){//注意是i是从2开始的 int c=0; for(j=0;j<=maxn-1;j++){
2014-11-30 15:00:55 429
原创 高精度运算之小学生算法
#include int main(void){ int a,b; while(scanf("%d %d",&a,&b)==2){ if(!a&&!b){//此时的a和b都不为0 break; } int c=0,ans=0; for(int i=9;i>=0;i--){ c=(a%10+b%10+c)>9?1:0; ans+=c; a/=10;
2014-11-30 14:28:06 321
原创 周期串
注意:1临时定义变量,比如i和j定义再循环体内,因此在循环体后就无法访问它们在使用前才定义变量能让程序更加清晰。但是这个语法不是ANSIC的所以程序的扩展名保存成.cpp#include #include int main(){ char word[100]; scanf("%s",word); int len=strlen(word); for(int i=1;i<=len;i++
2014-11-29 17:27:15 323
原创 TeX括号
#include int main(){ int c,q=1; while((c=getchar())!=EOF) { if(c=='"') { printf("%s",q?"``":"''"); q=!q; }else{ printf("%c",c); } } return 0;}
2014-11-29 17:20:02 324
原创 WERTYU
#include char *s="`1234567890-=QWERTYUIOP[]\ASDFGHJKL;'ZXCVBNM,./";int main(){ int i,c; while((c=getchar())!=EOF) { for(i=1;s[i]&&s[i]!=c;i++){ if(s[i]){ putchar (s[i-1]); }else{
2014-11-29 16:59:53 326
原创 位段的声明
有些信息只需要占一个或者几个二进制位,不需要占用一个完整的字节,为节省空间,所以产生了位段结构。位段就是把一个字节中的二进制划分为几个不同的区间,并说明每个区段的位数每个段有一个段名,允许在程序中按段名进行操作,这样就可以把几个不同的对象用一个字节的二进制位段来表示。位段的声明和位段变量的声明相仿:Struct 位段结构名{位段表};位段表的形式如下:类型说
2014-11-26 15:21:49 485
原创 stract函数的实现 连接str2到str1的后面
#include #include #include #define MAXN 50char *ownStrcat(char *str1,const char *str2);int main(void){ char array1[MAXN],array2[MAXN]; scanf("%s %s",array1,array2); ownStrcat(array1,array2);注
2014-11-18 19:22:35 2387
原创 定义结构记录学生分数,并由高到低排列出来
Define a struct type that contains a student’s number, name and score of three courses. Write a program, to enter 5 students’ information(name, number & scores of the 3 courses), and calculate the tot
2014-11-17 23:10:35 523
原创 联合变量的赋值和使用
#include #include #define N 3 int main(void){ struct { char name[10]; int age; char identity; union { int clas; char office[10]; }classOrOffice; }person[N]; int i; for(i=0;i
2014-11-17 22:04:54 1187
原创 结构类型指针变量的使用实例
#include #include #include int main(void){ struct DateType { int year; int month; int day; }; struct StudentType { int num; char *name; char sex[3]; struct DateType birthday;
2014-11-17 02:27:38 475
原创 建立同学通讯录
#include #include #define NUM 3int main(void){ struct MemberType { char name[20]; char phone[10]; }; struct MemberType menber[NUM]; int i; for(i=0;i<NUM;i++) { printf("\n输入第%d个人通讯信息:\
2014-11-17 01:06:47 1541
原创 结构类型数组实例(计算学生的平均人数以及及格人数)
#include #include #define N 6int main(void){ int i,countOfPass=0; float av,sum=0.0; struct StudentType { int num; char *name; char sex[3]; int age; float score; }; struct StudentTy
2014-11-17 00:42:26 821
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人