zoukankan      html  css  js  c++  java
  • 复试临时练习

      由于疫情原因,考研复试安排到15.16两天,对学校前两年的复试真题做了三遍,将C primer Plus也翻看了一下,战线太长,后劲儿不足;

    想到初试成绩排到倒数,还是想挣扎一下的。

    计算机的内容实在是太多太杂,查漏补缺(坑有些大了)

    //菲波拉契数前20项和 
    #include<stdio.h>
    #define N 20 
    int main()
    {
        int a[N]={1,1};
        int i,sum=0;
        for(i=0;i<N;i++)
        {
        if(i>1)  a[i]=a[i-1]+a[i-2];
        sum+=a[i];    
        }
        printf("前%d项和为%d",N,sum);
        return 0;
    }
    View Code
    //回文字符串判断
    #include<stdio.h> 
    #include<string.h>
    #define N 100
    int huiwen(char *p);
    int main()
    {
        char a[N];
        gets(a);
        int flag;
        flag=huiwen(a);
        if(flag) printf("回文字符串");
        else printf("非回文字符串");
        return 0;
    }
    int huiwen(char *p)
    {
        char *head,*tail;
        head=p;
        tail=strlen(p)-1+head;
        for(;head<=tail;head++,tail--){
            if(*head!=*tail) return 0;
            else return 1;
        }
    }
    View Code
    //回文数
    #include<stdio.h> 
    int main()
    {
        int num,s,y=0;
        scanf("%d",&num);
        s=num;
        while(s>0){
            y=y*10+s%10;
            s/=10;
        }
        if(y==num) printf("%d是回文数
    ",num);
        else printf("%d不是回文数
    ",num);
        return 0;
    }
    View Code
    //前n个数排序
    #include<stdio.h> 
    #define N 100
    int main()
    {
        int n,i,j,temp;
        printf("enter the count of number:");
        scanf("%d",&n);
        int a[n];
        for(i=0;i<n;i++)
        scanf("%d",&a[i]);
        for(i=1;i<n;i++)
        for(j=0;j<n-i;j++){
            if(a[j]>a[j+1]){
                temp=a[j];
                a[j]=a[j+1];
                a[j+1]=temp;
            }
        }
        for(i=0;i<n;i++)
        printf("%d	",a[i]);
        return 0;
    }
    View Code
    //统计字符类型
    #include<stdio.h> 
    int main()
    {
        char ch,alpha,digit,other;
        while((ch=getchar())!='
    '){
            if((ch>='a'&&ch<='z')||(ch>='A'&&ch<='Z')) alpha++;
            else if(ch>='0'&&ch<='9') digit++;
            else other++;
        }
        printf("字母:%d,数字:%d,其他:%d",alpha,digit,other);
        return 0;
    }
    View Code
    //材料剩余问题
    #include<stdio.h> 
    int main()
    {
        int min=800,i,j,a,b,reminder;
        for(i=0;i<=800/56;i++)
        for(j=0;j<=800/64;j++){
            reminder=800-56*i-64*j;
            if(reminder>=0){
                if(min>reminder){
                    min=reminder;
                    a=i;
                    b=j;
                }
            }
        }
        printf("A=%d,B=%d,min=%d",a,b,min);
        return 0;    
    }
    View Code
    //最小公倍数 
    #include<stdio.h>
    int main()
    {
        int m,n,temp,i;
        scanf("%d %d",&m,&n);
        if(m<n){
            temp=m;
            m=n;
            n=temp;
        }
        for(i=m;i>0;i++)
        if(i%m==0&&i%n==0)
        {
            printf("%d %d %d",m,n,i);
            break;
        }
        return 0;
    }
    View Code
    //最大公约数
    #include<stdio.h> 
    int main()
    {
        int m,n,i,temp;
        scanf("%d %d",&m,&n);
        if(m<n)
        {
            temp=m;
            m=n;
            n=temp;
        }
        for(i=n;i>=1;i--)
        if(m%i==0&&n%i==0)
        {
            printf("%d %d %d",m,n,i);
            break;
        }
        return 0;
    }
    View Code
    //单词计数,朋友指点的
    #include <stdio.h>
    #include <string.h>
    #define N 100
    int alpha(char* ch);
    int digit(char* ch);
    int main()
    {
        char ch[N];
        gets(ch);
        int a, b, c, n;
        n = strlen(ch);
        a = alpha(ch);
        b = digit(ch);
        c = n - a - b;
        printf("alpha:%d,digit:%d,other:%d", a, b, c);
        return 0;
    }
    int alpha(char *ch)
    {
        int i,sum = 0;
        for (i = 0; ch[i] != ''; i++)
        {
            if ((ch[i] >= 'a'&&ch[i] <= 'z') || (ch[i] >= 'A'&&ch[i] <= 'Z'))
            {
                sum++;
            }
    
        }
        return sum;
    }
    
    int digit(char *ch)
    {
        int i,sum = 0;
        for (i = 0; ch[i] != ''; i++)
        {
            if (ch[i]>='0'&&ch[i]<='9')
            {
                sum++;
            }
    
        }
        return sum;
    }
    View Code
  • 相关阅读:
    演练:创建和使用托管程序集 (C++)
    QT中各种MessageBox的使用
    QT使用打印机
    常用数据结构算法 c++模板实现
    创建可重用代码(C++)
    演练:创建和使用动态链接库 (C++)
    一些面试题,整理自网络,就不一一帖原址了
    《实践与思考》系列连载(4)——众说纷纭“架构师”
    XML Web Service并发异步调用的问题及其解决方案
    《实践与思考》书籍连载系列反馈区
  • 原文地址:https://www.cnblogs.com/shun998/p/12883476.html
Copyright © 2011-2022 走看看