国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發(fā)設計 > 正文

編程練習三

2019-11-11 03:27:45
字體:
來源:轉載
供稿:網友


程序一、編寫函數void count(char a[],char w[][10],int n,int b[])。功能是:統(tǒng)計w指向的數組中的n個單詞在a指向的字符串中各自出現的次數(將非字母字符看作單詞分割符),擰將統(tǒng)計結果依次保存在b指向的數組中。

#include <stdio.h>

#include <string.h>

#include <ctype.h>

 

void count(char a[], char w[][10], int n, int b[]);

 

int main()

{

    char a[100], w[10][10];

int b[100];

int n,i;

 

PRintf("Please inpu a string:/n");

scanf("%s", a);

printf("Please input the number of the Words:/n");

scanf("%d", &n);

    printf("Please input the words:/n");

for(i = 0; i < n; i++)

{

        scanf("%s", w[i]);

}

count(a, w,n,b);

 

    return 0;

}

 

void count(char a[], char w[][10], int n, int b[])

{

    int i, t;

int j = 0;

int k = 0;

int num = 0;

    int len_word;

int len_str = 0;

    

    for(i = 0; i < n; i++)

{

k = 0;

num = 0;

len_word = strlen(w[i]);

while(a[k] != '/0')

{

    len_str = 0;

j = 0;

if(isalpha(a[k]))

{   

while(a[k] == w[i][j] && a[k] != '/0')

{

len_str++;

k++;

j++;

}

}

if(len_word == len_str && !isalpha(a[k]))

{

num++;

}

            

k++;

}

b[i] = num;

}

 

for(i = 0; i < n; i++)

{

printf("%s=%d  ", w[i], b[i]);

}

printf("/n");

}

 

 

程序二、編寫函數int stat(int a[],int n,int c[][2])。a指向的數組中保存了由n個1位整數組成的數列(n為偶數)。函數從前至后依次將a數組中每兩個相鄰元素拼成一個不超過2位的整數,從而生成有n/2個元素組成的整數數列;統(tǒng)計該數列中不同整數各自出現的次數,并將統(tǒng)計結果保存到c指向的二維數組中。函數返回不同整數的個數。

#include <stdio.h>

 

int start(int a[], int n, int c[][2]);

 

int main()

{

int a[100];

int c[100][2];

int n, i;

 

printf("Please input a number:");

scanf("%d", &n);

 

if(n % 2 != 0)

{

printf("Please input a new number:");

scanf("%d", &n);

}

printf("Please input the numbers:/n");

for(i = 0; i < n; i++)

{

scanf("%d", &a[i]);

}

 

    start(a, n, c);

    

    return 0;

}

 

int start(int a[], int n, int c[][2])

{

int i;

int j = 0;

int num = 0;

 

for(i = 0; i < n; i +=2)  //組成n/2個數

{

          c[j++][0] = a[i] * 10 + a[i+1];

}

 

for(i = 0; i < n/2; i++)      //統(tǒng)計出現的次數

{

        for(j = 0; j < n/2; j++)

{

if(c[i][0] == c[j][0])

{

num++;

}

}

c[i][1] = num;

num = 0;

}

 

for(i = 0; i < n/2; i++)   

{

printf("%5d", c[i][0]);

printf("%5d", c[i][1]);

printf("/n");

}

printf("/n");

    

}


發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 绥化市| 嘉禾县| 奎屯市| 遂溪县| 杭州市| 兴城市| 桂东县| 徐汇区| 鄢陵县| 会理县| 宁远县| 修水县| 伊通| 孝感市| 石狮市| 万宁市| 平远县| 石城县| 奉节县| 大关县| 南昌县| 鲁甸县| 宜良县| 兴海县| 磴口县| 肥东县| 宣恩县| 思南县| 滨海县| 岳西县| 焉耆| 山东| 南华县| 钦州市| 乐安县| 天镇县| 延津县| 麻阳| 济阳县| 金阳县| 苗栗市|