字符串处理题.docx
- 文档编号:23670659
- 上传时间:2023-05-19
- 格式:DOCX
- 页数:16
- 大小:19.06KB
字符串处理题.docx
《字符串处理题.docx》由会员分享,可在线阅读,更多相关《字符串处理题.docx(16页珍藏版)》请在冰豆网上搜索。
字符串处理题
18道全在这很多都是写了蛮早了所有代码有点乱效率也不是很高就当参考吧
时间太紧了现在还有事就直接从我账号里复制出来了int跟mian和在一起了自己改一下吧
1001
#include
usingnamespacestd;#definemax100000
intdnum[max];intdaoxu(intp1)
{intp2=0,p3=p1;while(p3>0)
{
p2=p2*10+p3%10;
p3/=10;
}if(p2==p1)return0;else
returnp2+p1;
}intmain()
{intc,i;while(cin>>dnum[0])
{
c=0;while(daoxu(dnum[c])!
=0)
{
dnum[c+1]=daoxu(dnum[c]);
c++;
}
cout< cout<<"--->"< cout< }return0; } 1002 #include intmain(void) {inti,j,k,b,n;charm[500]; scanf("%d",&n); getchar();for(i=0;i { k=0;for(b=0;m[b]! ='\0';b++) { m[b]='\0'; } gets(m);for(j=0;m[j]! ='\0';j++) {if(m[j]>='0'&&m[j]<='9') k++; } printf("%d\n",k); } return0; } 1003 #include #include intmain() {inti,j,k,n,m;chara,buffer[50];intidentf(char*str); scanf("%d",&n); a=getchar();for(i=0;i { k=0; gets(buffer);if(identf(buffer)) printf("yes\n");else printf("no\n"); }return0; }intidentf(char*str) {intflag=0;char*p=str;if((*str>='a'&&*str<='z')||(*str>='A'&&*str<='Z')||*str=='_') { flag=1; str++; }while(*str&&flag) {if((*str>='a'&&*str<='z')||(*str>='A'&&*str<='Z')||*str=='_'||(*str>='0'&&*str<='9')) { flag=1; str++; }else flag=0; }returnflag;} 1004 #include #include intmain() {intn,i;charch[100];while(gets(ch)) { n=strlen(ch); ch[0]-=32;for(i=0;i {if(ch[i]=='') ch[i+1]-=32; } puts(ch); }return0; } 1005 #include usingnamespacestd;intmain() {inti,j,k,c,high,wide,h1,h2,num1;charch; cin>>c;for(i=0;i { cin>>ch>>high; num1=high-3;if(num1%2==0) h1=h2=num1/2;else{ h1=num1/2; h2=h1+1; } wide=high/6+1; k=1;while(k<=high) {if(k==1||k==h1+2||k==high) {for(j=0;j {if(j cout<<"";else cout< } cout< k++; }else{for(j=0;j<2*wide+h2;j++) {if(j cout< cout<<""; } cout< k++; } }if(i! =c-1) cout< }return0; } 1006 #include #include #include #include usingnamespacestd;intmain(void) { set strings="";charc;while((c=getchar())! ='#') { s+=c;while(c! ='\n') {while((c=getchar())! =''&&c! ='\n') s+=c;if(s.length())st.insert(s); s=""; } cout< st.clear(); }return0; } 1007 #include #include intmain() {inta,b,c,d;inti,j;intl,n,sum;charch[50]; scanf("%d",&n); getchar();for(i=0;i { a=0;b=0;c=0;d=0;sum=0; gets(ch); l=strlen(ch);for(j=0;j {if(ch[j]>='a'&&ch[j]<='z') {a=1;}elseif(ch[j]>='A'&&ch[j]<='Z') {b=1;}elseif(ch[j]>='0'&&ch[j]<='9') {c=1;}elseif(ch[j]=='~'||ch[j]=='! '||ch[j]=='@'|| ch[j]=='#'||ch[j]=='$'||ch[j]=='%'||ch[j]=='^') {d=1;} } sum=a+b+c+d;if(sum>=3&&l>=8&&l<=16) printf("YES\n");else printf("NO\n"); }return0; } 1008 #include usingnamespacestd;intmain() {chara[10];while(cin>>a) {if(! strcmp(a,"0")){cout<<"zero"< {intk=strlen(a)-i;if(k==3&&i==1&&a[i]! ='0')cout<<"and";if(k==2&&i>=1&&(a[i]! ='0'||a[i+1]! ='0'))cout<<"and";if(k! =2) {if(a[i]=='1')cout<<"one";elseif(a[i]=='2')cout<<"two";elseif(a[i]=='3')cout<<"three";elseif(a[i]=='4')cout<<"four";elseif(a[i]=='5')cout<<"five";elseif(a[i]=='6')cout<<"six";elseif(a[i]=='7')cout<<"seven";elseif(a[i]=='8')cout<<"eight";elseif(a[i]=='9')cout<<"nine"; }if(k==4)cout<<"thousand";if(k==3&&a[i]! ='0')cout<<"hundred";if(k==2) {if(a[i]=='1') {if(a[i+1]=='0')cout<<"ten";elseif(a[i+1]=='1')cout<<"eleven";elseif(a[i+1]=='2')cout<<"twelve";elseif(a[i+1]=='3')cout<<"thirteen";elseif(a[i+1]=='4')cout<<"fourteen";elseif(a[i+1]=='5')cout<<"fifteen";elseif(a[i+1]=='6')cout<<"sixteen";elseif(a[i+1]=='7')cout<<"seventeen";elseif(a[i+1]=='8')cout<<"eighteen";elseif(a[i+1]=='9')cout<<"nineteen"; cout< }elseif(a[i]=='2')cout<<"twenty";elseif(a[i]=='3')cout<<"thirty";elseif(a[i]=='4')cout<<"forty";elseif(a[i]=='5')cout<<"fifty";elseif(a[i]=='6')cout<<"sixty";elseif(a[i]=='7')cout<<"seventy";elseif(a[i]=='8')cout<<"eighty";elseif(a[i]=='9')cout<<"ninety"; }if(k==2&&a[i]! ='0'&&a[i+1]! ='0')cout<<'-';if(k==1)cout< } }return0; } 1009 #include #include usingnamespacestd;intmain() {inti,j,k,num[1000];intc,ch2,m;while(cin>>c) {for(i=0;i scanf("%d",&num[i]); k=0;for(i=65;i<=90;i++) {for(j=0;j {if((i^num[j])<65||(i^num[j])>90) { k=0;break; }else k=1; }if(k==1) { ch2=i;break; } }for(i=0;i { m=num[i]^ch2; printf("%c",m); } printf("\n"); }return0; } 1010 #include usingnamespacestd;#include #defineMAX1000000 chara[MAX],b[MAX];intmain() {inti,j,k,l1,l2;while(cin>>a>>b) { l1=strlen(a); l2=strlen(b);for(i=0;i {if(a[i]=='.')break; }for(j=0;j {if(b[j]=='.')break; }for(k=l1-1;k>=i;k--) {if(a[k]=='0'||a[k]=='.') a[k]='\0';else break; }for(k=l2-1;k>=j;k--) {if(b[k]=='0'||b[k]=='.') b[k]='\0';else break; }if(strcmp(a,b)==0) cout<<"YES"< cout<<"NO"< }return0; } 1011 #include #include intmain() {charch1[5],ch2[100];intnum[100],i,j,l1,l2;while(gets(ch1)&&ch1[0]! ='#') { gets(ch2); l1=strlen(ch1); l2=strlen(ch2);for(i=0;i num[i]=0;for(i=0;i {if(ch1[i]==ch2[j]) num[i]++; }for(i=0;i printf("%c%d\n",ch1[i],num[i]); }return0; } 1012 #include intmain() {inti,n;charbox[1002];while(scanf("%s",&box)! =EOF) { n=0;for(i=0;box[i]! ='B';i++) {if(box[i]=='(') n++;elseif(box[i]==')') n--; } printf("%d\n",n); }return0; } 1013 #include #include usingnamespacestd;#defineMAX10002 charLOCK[MAX],key;intnum[MAX]; Intmain() {intTEST,k,len,i; cin>>TEST;while(TEST--) { cin>>LOCK; len=strlen(LOCK); k=0;for(i=0;i num[i]=0; for(i=0;i {if(LOCK[i]=='#') { cout<<"";continue; }if(LOCK[i]=='-')continue; num[k]=LOCK[i]-48;if(LOCK[i+1]! ='#'&&LOCK[i+1]! ='-'&&i! =len-1) { num[k]=num[k]*10+LOCK[i+1]-48; i++; } key=num[k]+64; cout< k++; } cout< }return0; } 1014 #include #include usingnamespacestd;chara[201],b[11],c[4]; voidpailie() {char*p=a;while(*p! ='\0') {if(*p>='A'&&*p<='Z') { *p-=5;if(*p<'A')*p+=26; } p++; } } Intmain() {while (1) { cin.getline(b,11);if(! strcmp(b,"ENDOFINPUT"))return0; cin.getline(a,201); cin.getline(c,4); pailie();
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 字符串 处理