打印小写字母表
#include<iostream>
#include<string.h>
#include<iomanip>
#include<stdio.h>
#include<cmath>
using namespace std;
int main()
{char n='a';for(int i=1;i<=13;i++){cout<<n;n++;}cout<<endl;for(int i=1;i<=13;i++){cout<<n;n++;}cout<<endl;n='z';for(int i=1;i<=13;i++){cout<<n;n--;}cout<<endl;for(int i=1;i<=13;i++){cout<<n;n--;}cout<<endl;return 0;
}
时间的差
#include<iostream>
#include<string.h>
#include<iomanip>
#include<stdio.h>
#include<cmath>
using namespace std;
int main()
{char a[2000],b[2000];int c=0;cin>>a;cin>>b;int am=0;int bm=0;int la=strlen(a);int lb=strlen(b);am=am+(a[1]*10+a[2])*3600+(a[4]*10+a[5])*60+a[7]*60+a[8];bm=bm+(b[1]*10+b[2])*3600+(b[4]*10+b[5])*60+b[7]*60+b[8];cout<<bm-am;return 0;
}
数字和
#include<stdio.h>
#include<stream>
#include<string.h>
int main()
{char a[205];int i,b[205],l,sum=0;cin<<a;l=strlen(a);for(i=0;i<l;i++){b[i]=a[i]-'0';sum=sum+b[i];}cout<<sum;return 0;
}
国王的魔镜
#include<stdio.h>
#include<string.h>
int main()
{int n;cin>>n;while(n--){char a[100];int l,i,b;gets(a);l=strlen(a);if(l%2!=0){cout<<1;}else{while(l>1&&l%2==0){b=0;for(i=0;i<l/2;i++){if(a[l/2-i-1]==a[l/2+i]){b++;}}if(b==l/2){l/=2;}elsebreak;}cout<<l;}}return 0;
}
简单解密
#include<stdio.h>
#include<string.h>
using namespace std;char s[100];int main()
{gets(s);for (int i = 0; i < strlen(s); i++){if (s[i] >= 'A' && s[i] <= 'E'){s[i] += 21;}else if (s[i] >= 'F' && s[i] <= 'Z'){s[i] -= 5;}}cout<<s;return 0;
}
查字典码中最小的字符串
#include<stdio.h>
#include<iostream>
#include<string.h>
using namespace std;
int main()
{char s[100],min[100];int n;cout<<n;gets(s);strcpy(min,s);for(int i=1;i<n;i++){gets(s);if(strcmp(min,s)>0){strcpy(min,s);}}cout<<min; return 0;
}
出现最多的小写字母
#include<iostream>
using namespace std;
int a[200];
string s;
int main() {cin>>s;for(int i=0; i<s.size(); i++) {a[s[i]]++;}int ma=97;for(int i=98; i<=122; i++) {if(a[i]>=a[ma]) {ma=i;}}char c=ma;cout<<c;return 0;
}
判断是否构成回文
#include<iostream>
using namespace std;
int main()
{
char ch,letter[101];
cin>>ch;
int i=0,j=1;
while(ch!='.')
{
++i;
letter[i]=ch;
cin>>ch;
}
while((j<i)&&(letter[j]==letter[i]))
{
--i;++j;
}
if(j>=i) cout<<"yes"<<endl;
else cout<<"no"<<endl;
return 0;
}
移动个空格
#include<iostream>
#include<stdio.h>
using namespace std;
int main()
{char a[1000];cin.getline(a,1000);bool temp = true;int sign = 0;int i = 0;while(i != 1000){if(a[i] == ' ' && temp == true){temp = false;sign = i;}if(a[i] !=' ' && temp == false){temp = true;/a[sign] = a[i];a[i] = ' ';i = sign;}i++;}cout<<a;return 0;
}
删除*
#include<stdio.h>
#include <string.h>
main()
{int i,j,k=0,c;char a[100]={0}, b[100]={0}, d[100]={0}, e[100]={0}; gets(a);//输入c=strlen(a);//计算长度for (i=0;a[i]=='*';i++){b[i]=a[i]; }for (j=c-1;a[j]=='*';j--){d[k++]=a[j]; k=0;for(j=0;a[j]!='\0';j++){if (a[j]!='*')e[k++]=a[j]; }/*连接并输出*/strcat(b,e);strcat(b,d);puts(b);
}
字符串反码
#include<stdio.h>
#include<string.h>
int main()
{char s1[80];int m='a'+'z',n='A'+'Z';while(1){gets(s1);if(strcmp(s1,"!")==0)return 0;char *p=&s1[0];while(*p!='\0'){if(*p>='a'&&*p<='z')printf("%c",m-*p);else if(*p>='A'&&*p<='Z')printf("%c",n-*p);elseprintf("%c",*p);p++;}printf("\n");}return 0;
}
看完动漫要几天?不会
时钟旋转不会
字符串加密
#include<stdio.h>
#include<string.h>
int main()
{char str[100];while(gets(str)!=NULL){int i,length=0;length=strlen(str);for(i=0;i<length;i++){if(str[i]>='A'&&str[i]<='Z'||str[i]>='a'&&str[i]<='z')str[i]=(int)str[i]+1;if((int)str[i]>122)str[i]=(int)str[i]-57;}puts(str);printf("\n");}return 0;
}