u013421512
coco1312
采纳率30.2%
2015-08-02 09:35 阅读 2.1k

求大侠帮忙:C语言程序设计---编程题(以下所有题目程序应是非递归的)

  1. 编写一个函数insert(s1,s2,ch),实现在字符串s1中的指定字符ch位置处插入字符串s2.
  2. 学校工会组织活动,要求有8名教师参加,这8名教师将分别从A学院3名教师、B学院5名教师、C学院6名教师中任意抽取,且其中必须有B学院的教师参加,请编程输出所有可能的方案
  3. 已知在C盘根目录下存有文本文件“file1.txt”,编程统计文件“file1.txt”中每个字母字符和每个数字字符出现的频率,在屏幕上显示统计结果,并将统计结果写入磁盘文件“file2.txt”中
  4. 输入一个字符串,内有数字和非数字字符,如:AS234fgh456d 17968x7654,将其中连续的数字作为一个整体,依次存放到一数组a中,例如234存入a[0],456存入a[1],…,编程统计其共有多少个整数,并输出这些数。要求: 1) 编写函数完成将字符串中连续的数字作为一个整体,依次存放到一数组a中 2) 在主函数中完成数据的输入与结果的输出
  5. 按由大到小的顺序对一个含有N个整型数据的数组A[N]进行排序,利用如下改进的选择排序方法:第一次选出最大者存入A[1],第二次选出最小者存入A[N],第三次选出次大者存入A[2],第四次选出次小者存入A[N-1],如此大小交替地选择,直到排序完成。要求: 1) 编写函数sort完成排序 2) 在主函数中完成数据的输入与结果的输出
  6. 已知用两个单链表分别存储的两个字符串,均按递增次序排列。编程实现将这两个单链表归并为一个按数据域值递减次序排列的单链表。要求: 1) 单链表中每个结点只存放一个字符 2) 利用原链表中的结点空间存储归并后的单链表,不另外生成新链表 3) 单链表的建立写一函数create实现 4) 两个链表归并过程写一函数sub实现 5) 输出结果写一函数output实现 6) 主函数调用这三个函数完成程序功能
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

4条回答 默认 最新

  • caozhy 从今以后生命中的每一秒都属于我爱的人 2015-08-02 22:07
  • yyfbuzhidao yyfbuzhidao 2015-08-03 16:29

    int main()
    {

    int i = 0;
    int iCount = 1;
    for (;i <= 3;i++)
    {
        int j = 1;
        for (;j <= 5;j++)
        {
            int k = 0;
            for (;k <= 6;k++)
            {
                if (8 == (i + j + k ))
                {
                    printf("第%d种方案:A学院%d名,B学院%d名,C学院%d名\n",iCount++,i,j,k);
                }
    
            }
        }
    }
    getchar();
    return 0;
    

    }

    点赞 评论 复制链接分享
  • yyfbuzhidao yyfbuzhidao 2015-08-04 01:56

    第五个,网上随便找个排序方法(冒泡,选择,插入,希尔,堆,快排,归并)就行了

    点赞 评论 复制链接分享
  • yyfbuzhidao yyfbuzhidao 2015-08-04 13:46

    #include
    #include "string.h"

    struct ListNode
    {
    ListNode *pNext;
    char cValue;
    };

    int create(ListNode *&pHead,const char *pStr)
    {
    if (NULL == pStr || '\0' == *pStr)
    {
    return -1;
    }

    pHead = (ListNode *)malloc(sizeof(ListNode));
    pHead->pNext = NULL;
    pHead->cValue = *pStr;
    pStr++;
    while (*pStr)
    {
        ListNode *pTemp = pHead;
        ListNode *pTemp2 = pHead; 
        while (NULL != pTemp)
        {
            if (pTemp->cValue >= *pStr)
            {
                break;
            }
            pTemp2 = pTemp;
            pTemp = pTemp->pNext;
        }
        ListNode *pNew = (ListNode *)malloc(sizeof(ListNode));
        pNew->cValue = *pStr;
        if (pHead == pTemp)
        {
            pNew->pNext = pHead;
            pHead = pNew;
            if (pHead->cValue > pHead->pNext->cValue)
            {
                pHead->cValue = pHead->pNext->cValue;
                pHead->pNext->cValue = *pStr;
            }
        }
        else if (NULL == pTemp2->pNext)
        {
            pTemp2->pNext = pNew;
            pNew->pNext = NULL;
        }
        else
        {
            pNew->pNext = pTemp2->pNext;
            pTemp2->pNext = pNew;
        }
        pStr++;
    }
    
    return 0;
    

    }

    void output(ListNode *pHead)
    {
    if (NULL == pHead)
    {
    return;
    }
    while (NULL != pHead)
    {
    printf("%c",pHead->cValue);
    pHead = pHead->pNext;
    }
    printf("\n");
    }

    int sub(ListNode *pHead1,ListNode *pHead2,ListNode *&pHead)
    {
    if (NULL == pHead1 || NULL == pHead2)
    {
    return -1;
    }
    ListNode *pTail = NULL;
    if (pHead1->cValue < pHead2->cValue)
    {
    pHead = pHead1;
    pHead1 = pHead1->pNext;
    pTail = pHead;
    }
    else
    {
    pHead = pHead2;
    pHead2 = pHead2->pNext;
    pTail = pHead;
    }

    while (NULL != pHead1 && NULL != pHead2)
    {
        if (pHead1->cValue < pHead2->cValue)
        {
            pTail->pNext = pHead1;
            pTail = pHead1;
            pHead1 = pHead1->pNext;
        }
        else
        {
            pTail->pNext = pHead2;
            pTail = pHead2;
            pHead2 = pHead2->pNext;
        }
    }
    
    while (NULL != pHead1)
    {
        pTail->pNext = pHead1;
        pTail = pHead1;
        pHead1 = pHead1->pNext;
    }
    while (NULL != pHead2)
    {
        pTail->pNext = pHead2;
        pTail = pHead2;
        pHead2 = pHead2->pNext;
    }
    
    pHead1 = pHead->pNext;
    pHead2 = pHead;
    
    while (NULL != pHead1)
    {
        ListNode *pTemp = pHead1->pNext;
        pHead1->pNext = pHead;
        pHead = pHead1;
        pHead1 = pTemp;
    }
    pHead2->pNext = NULL;
    return 0;
    

    }

    int main()
    {

    const int MAX_SIZE = 1024;
    printf("请输入链表1(字符串长度不超过%d):\n",MAX_SIZE);
    char szBuff[MAX_SIZE] = {0};
    if (0 == scanf_s("%s",&szBuff,sizeof (szBuff)))
    {
        printf("输入的字符串不对\n");
        getchar();
        return -1;
    }
    ListNode *pHead1 = NULL;
    create(pHead1,szBuff);
    printf("链表1为:");
    output(pHead1);
    
    printf("请输入链表2(字符串长度不超过%d):\n",MAX_SIZE);
    if (0 == scanf_s("%s",&szBuff,sizeof (szBuff)))
    {
        printf("输入的字符串不对\n");
        getchar();
        return -1;
    }
    ListNode *pHead2 = NULL;
    create(pHead2,szBuff);
    printf("链表2为:");
    output(pHead2);
    
    ListNode *pHead = NULL;
    sub(pHead1,pHead2,pHead);
    printf("\n新链表为:");
    output(pHead);
    
    while (NULL != pHead)
    {
        ListNode *pTemp = pHead->pNext;
        free(pHead);
        pHead = pTemp;
    }
    
    while (1);
    return 0;
    

    };

    点赞 评论 复制链接分享

相关推荐