中国石油大学第八章计算机作业(china university of petroleum eighth chapter computer homework)
(31页)
本资源提供全文预览,点击全文预览即可全文预览,如果喜欢文档就下载吧,查找使用更方便哦!
29.9 积分
中国石油大学第八章计算机作业(中国石油大学第八章计算机作业(ChinaChina UniversityUniversity ofof PetroleumPetroleum eightheighth chapterchapter computercomputer homeworkhomework))8.1 character conversiondescribeExtract all the numeric characters in a string ('0'... '9') and convert it to an integer output.inputA string with the carriage return as the end mark (less than 80 characters).outputConverts all numeric characters in a string ('0'... '9') to an integer and outputs it.#includeInt main (){Char str[80];Int i, m=0;Gets (STR);For (i=0; str[i]; ='\0'; i++){If (str[i]='0'){M=m*10+ (str[i]-48);}}Printf (“%d\n“, m);}8.2 merge stringsInput two strings that have been arranged in order from small to large, write a function that combines two strings, so that the merged string is still from small to large arrangement.Input:Two strings that have been arranged in order (ascending)Output:An ordered (ascending) string merged together#include #include #include Int main (){Char a[100], b[100], t;Int k, I, j;Gets (a);Gets (B);Strcat (a, B);K=strlen (a);For (j=1; j=a[i+1]){T=a[i];A[i]=a[i+1];A[i+1]=t;}Puts (a);Return 0;}8.3 delete duplicate charactersBackground:Enter a string of no more than 100, and delete the duplicate characters in the string.Input:Enter a string to check, not more than 100 characters long. For example: abacaeedabcdcd.Output:String after deleting duplicate characters. For example: abced.#include Int main (){Char a[100], b[100];Int n, I, J, cnt=1;Gets (a);N=strlen (a);B[0]=a[0];For (i=1; iInt main (){Char a[100], b[100], c[100];Int m, N, I, J, k=0, P, q;Gets (a);Gets (B);N=strlen (a);M=strlen (B);For (i=0; i y? x: y;for (i = x - 1; i > = 0; i --)c [x - in - 1] = a [i] - '0';for (j = y - 1; j > = 0; i --)d [y - j - 1] = b [j], '0';for (i = 0; i 9){if (i = = m - 1)m + +;e [i + 1] + +;e [in] = 10;}}for (i = m - 1; i > = 0; i --)printf (“% d“, e [i]);printf (“\ n“);}字符串重排列 8.9判断一个字符串是否可以由另一个字符串通过重排字符而得到.注意, 此处区分字符大小写!输入输入只有一行, 为两个字符串, 字符串之间以一个空格分隔.输出如果两个字符串由同一组字符组成 (且每一个字符出现次数相同), 则输出 “yes“;否则输出 “no“.注意 yes 和 no 都是大写字母!# include stdio.h > = '0' sum = 0;}}}8.13 判断字符串是否为回文编程, 输入一个字符串, 输出该字符串是否回文.关于输入输入为一行字符串 (字符串中没有空白字符, 字符串长度不超过100).关于输出If the string is palindrome, output yes; otherwise, output No.#include#includeInt main (){Int i, J, t, p=0;Char a[100];Gets (a);T=strlen (a);J=t-1;For (i=0; iInt main (){Int i;Char a[100];Gets (a);If (a[0]>=97Char a[100][100];Scanf (“%d“, For (i=0; i
天天文库所有资源均是用户自行上传分享,仅供网友学习交流,未经上传用户书面授权,请勿作他用。
关于本文
本文标题:中国石油大学第八章计算机作业(china university of petroleum eighth chapter computer homework)
链接地址: https://www.wenku365.com/p-8538160.html