收藏 分销(赏)

技能训练十二字符串试卷.doc

上传人:仙人****88 文档编号:7398877 上传时间:2025-01-02 格式:DOC 页数:7 大小:30KB 下载积分:10 金币
下载 相关 举报
技能训练十二字符串试卷.doc_第1页
第1页 / 共7页
技能训练十二字符串试卷.doc_第2页
第2页 / 共7页


点击查看更多>>
资源描述
字符串 1、用插入法将如下字符串按升序输出,DV,DVD,VCD,ROM,RAM,DDR,TCP,IP,BUS. #include <string.h> #include <stdio.h> main() { char a[9][4]= {"DV","DVD","VCD","ROM","RAM","DDR","TCP","IP","BUS"},b[4]; int i,j; for(i=0; i<9; i++) printf("%s ",a[i]); printf("\n"); for (i=1; i<9; i++) { J= ; ; while ( ) { ; j--; } ; } for(i=0; i<9; i++) printf("%s ",a[i]); printf("\n"); } 2、下列程序的功能是:将读入的一行字符中的小写全部转换成对应的大写字母后第二个字母,其中字母Y转换成A、字母Z转换成B. #include <stdio.h> #include <string.h> main() { char a[20]; int n,i; gets(a); ; printf("%s\n",a); for(i=0;i<n;i++) { if (a[i]>='a'&&a[i]<='z') { if(a[i]>90&&a[i<=92]) } } printf("%s\n",a); } 3、十进制数转换成二进制数 #include <stdio.h> #include <string.h> #include <math.h> void main() {     int n, m, i=0;     char s[16];     printf ("Please input a num: ");     scanf("%d", &n);     n = abs(n);     m = n;     while ( )     {         ;         m /= 2;     }     ;     for (; i>=0; i--)         printf("%d", s[i]);     printf("\n"); } 4、将N个元素的字符串数组中,含有”COM”(大小写)元素全部显示出来 #include <stdio.h> #include <string.h> void main() { char s[][20] = {"hello", "acond", "command", "this", "heauly", "dbcCOMD", "DDcOM", "fullbloom"}; int i, n = sizeof(s)/sizeof(char[20]); char str[10]; for (i=0; i<n; i++) { ; if (strstr(strlwr(str), "com") != 0) puts(s[i]); } } 5、输入任一15位以内的正整数,即能输出组成此数的所有数字之和SUM. #include <stdio.h> #include <string.h> main() { char arr[30]; int i,n,sum; ; puts(arr); n=strlen(arr); sum=0; for(i=0;i<n;i++) ; printf("%d",sum); } 6、输入一行文字,统计其中单词的个数以及英文字母(不区分大小字)出现的频率。为简化运算,规定单词之间由空格做间隔,且文本行中不含有其他字符。 方法一、 #include <stdio.h> #include <string.h> main() { char arr[40]; int n,i,word=0,count=0,m[26]= {0},k; gets(arr); puts(arr); n=strlen(arr); for(i=0; i<n; i++) if ( ) word=0; else if( ) { word=1; ; } printf("%d\n",count); strlwr(arr); for (i=0; i<n; i++) { k= ; ; } for (i=0;i<26;i++) if (m[i]!=0) printf("%c出现的次数为:%d\n",97+i,m[i]); } 方法二、 #include <stdio.h> #include <string.h> main() { char arr[40]; int n,i,word=0,count=0,m[26]= {0},k; gets(arr); puts(arr); n=strlen(arr); for(i=0; i<n; i++) { while(arr[i]==' ') i++; while(arr[i]!=' '&&arr[i]) i++; ; } printf("%d\n",count); strlwr(arr); for (i=0; i<n; i++) { k=arr[i]-97; m[k]++; } for (i=0; i<26; i++) if (m[i]!=0) printf("%c出现的次数为:%d\n",97+i,m[i]); } 7、有一段文字“This is a disk.This is a desk.编程找出“is”出现的次数和在字符串的位置。 #include <stdlib.h> #include <time.h> #include <stdio.h> main() { int i, j, k=0; char s1[100], s2[10], s3[11]= {0}, *p=NULL; printf("Please input text string: "); gets(s1); printf("Please input mode string: "); gets(s2); /* 1 */ printf("1'way:\n"); for (i=0; i<strlen(s1); i++) { for (j=0; j<strlen(s2); j++) if( ) break; if ( ) { k++; printf("%d's position is %d\n", k, i+1); } } /* 2 */ printf("2'way:\n"); for(i=0;s1[i]!=0;i++) { for(j=0;s1[i+j]!=0&&s2[j]!=0;) if( ) j++; else { i++; j=0; } if( ) ( k++; printf("%d's position is %d\n", k, ); ) if(s1[i+j]==0) break; } /* 3 */ printf("3'way:\n"); p = s1; k = 0; while (p = strstr(p, s2)) { k++; printf("%d's position is %d\n", k, p-s1+1); p++; } 8、随机产生一个包含10个大写英文字母的字符串,将其中ASCII码大于75的字母用ASCCI码代替。 #include <stdio.h> #include <stdlib.h> #include <time.h> main() { char str[11],str1[20]; int i,n=-1,t,a,b; srand((unsigned)time(NULL)); for (i=0; i<10; i++) str[i]=rand()%26+65; str[i]='\0'; printf("%s\n",str); for(i=0; i<10; i++) if(str[i]<=75) { n++; str1[n]=str[i]; } else { t=str[i]; a=t/10; b=t%10; n++; str1[n]= ; n++; str1[n]= ; } n++; str1[n]='\0'; printf("%s",str1); } /* 3 */ srand((unsigned)time(NULL)); for (i=0; i<10; i++) s3[i] = rand()%26+'A'; puts(s3); for (i=0; i<10; i++) { if (s3[i] > 75) printf(" ", s3[i]); else putch(s3[i]); } printf("\n"); } 9、从键盘上输入一个字符串S,进行括号匹配检查,规则是:(1)字符串S中的左括号“(”和右括号“)”相等;(2)、字符串从前向后检查时,遇到的右括号数在任何时候不超过左括号数。若满足上述条件,程序输出“SUCCESS”,否则输出“ERROR”. #include <stdio.h> #include <string.h> void main() { char s[100]; int i, j, k = 0, n; gets(s); n = strlen(s); for (i=0; i<n; i++) { if (s[i] == '(') k++; else if (s[i] == ')') k--; if (k<0) break; } if (k == 0) printf("SUCCESS\n"); else printf("ERROR\n"); } 7
展开阅读全文

开通  VIP会员、SVIP会员  优惠大
下载10份以上建议开通VIP会员
下载20份以上建议开通SVIP会员


开通VIP      成为共赢上传

当前位置:首页 > 教育专区 > 小学其他

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        抽奖活动

©2010-2026 宁波自信网络信息技术有限公司  版权所有

客服电话:0574-28810668  投诉电话:18658249818

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :微信公众号    抖音    微博    LOFTER 

客服