zoukankan      html  css  js  c++  java
  • 实验10 指针2

    1.输入一个字符串和一个正整数x,将该字符串中的后x个字符复制到另一个字符串y中,输出字符串y;再对y串的内容前后倒置后存入数组z中并输出。
         要求:用指针访问数组元素、用函数getx(char *c1)实现复制、用函数getr(char *c2)实现倒置。
         运行示例
         Enter a string: abcABCD
         Enter an integer: 4
         The new string is: ABCD
         The invert string is: DCBA

    2.为了防止信息被别人轻易窃取,需要把电码明文通过加密方式变换成为密文。变换规则是:小写字母z变换成为a,其它字符变换成为该字符ASCII码顺序后1位的字符,比如o变换为p。
         要求输入一个字符串(少于80个字符),输出相应的密文;要求定义和调用函数encrypt(s),该函数将字符串s变换为密文。

    #include<stdio.h>
    #include<string.h>
    void encrypt(char *s);
    int main()
    {
        char str[80];
        
        printf("请输入一串字符:");
        gets(str);
        encrypt(str);
        printf("After being encrypted:%s
    ",str);
        return 0;
    }
    void encrypt(char *s){
        for(;*s!='';s++)
            if(*s=='z')
                *s='a';
            else
                *s=*s+1;
    }

     3.请编一个程序,可以将英语规则名词由单数变成复数。已知规则如下:
         (a)以辅音字母y结尾,则将y改成i,再加es;
         (b)以s、x、ch、sh结尾,则加es;
         (c)以元音字母o结尾,则加es;
         (d)其他情况直接加s。
         要求用键盘输入英语规则名词,屏幕输出该名词的复数形式。

    #include<stdio.h>
    #define MAXLINE 200
    int main()
    {
        int a[MAXLINE];
        int i,n,count=0,index;
        
        printf("Input a number:");
        scanf("%d",&n);
        index=n;
        for(i=0;i<n;i++){
            a[i]=0;
        }
        i=0;
        while(n>1){
            if(a[i]==0){
                count++;
                if(count==3){
                    a[i]=1;
                    printf("%d号退出
    ",i);
                    n--;
                    count=0;
                }
            }
            i++;
            if(i==index)
                i=0;
        }
        for(i=0;i<index;i++){
            if(a[i]==0)
                printf("最后留下人的编号:%d",i);
        }
        return 0;
    }
  • 相关阅读:
    (转帖) oracle是否归档模式及修改模式
    (转帖) Oracle实例恢复(Oracle instance recovery)
    实习第一周总结
    UML类图几种关系的总结
    表格排序
    利用js查找页面中的内链,外链
    事件机制(事件冒泡与事件捕获)
    谈 CSS 模块化
    初学后台框架总结篇二——快速了解CI框架
    初学后台框架总结篇一——学习过程
  • 原文地址:https://www.cnblogs.com/simple9495/p/3417450.html
Copyright © 2011-2022 走看看