做了一下大一的字符串题 主要是练习一下string的用法
地址:http://acm.sdut.edu.cn/sdutoj/contest_show.php?contest_id=1136
第一题:
#include<iostream>
#include<string>
using namespace std;
int main()
{
string str1,str2;
while(cin>>str1>>str2)
{
if(str1==str2)
cout<<str1<<"="<<str2<<endl;
if(str1<str2)
cout<<str1<<"<"<<str2<<endl;
if(str1>str2)
cout<<str1<<">"<<str2<<endl;
}
return 0;
}
第二题:
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
struct xinxi{
string name;
int score;
}ren[11];
int cmp(xinxi x,xinxi y)
{ if(strcmp(str1,str2,))
return x.name<y.name;
}
int main()
{
int n;
n=10;
for(int i=1;i<=n;i++)
{
cin>>ren[i].name;
}
for(int i=1;i<=n;i++)
{
cin>>ren[i].score;
}
sort(ren,ren+10,cmp);
for(int i=1;i<=n;i++)
{
cout<<ren[i].name<<","<<ren[i].score<<endl;
}
return 0;
}
第三题:
#include<iostream>
using namespace std;
#include<string>
int main()
{
string str1,str2;
while(cin>>str1>>str2)
{
str1.append(str2);
cout<<str1<<endl;
}
return 0;
}
第四题:
#include<iostream>
#include<string>
#include<string.h>
using namespace std;
int main()
{
string str1,str2;
while(cin>>str1>>str2)
{
int ok=str1.find(str2,0);
if(ok!=-1)
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}
return 0;
}
第五题:
#include<iostream>
#include<string>
#include<cstring>
#include<stdio.h>
using namespace std;
int main()
{
char buf[100000];
char xin[100000];
int k;
int len1,len2;
while(gets(buf))
{
if(strcmp(buf,"2013")==0) break;
// cout<<buf<<endl;
len1=strlen(buf);
k=0;
for(int i=0;i<=len1;i++)
{
if(buf[i]==' ')
continue;
xin[k++]=buf[i];
}
len2=strlen(xin);
int ok=1;
for(int i=0;i<=len2;i++)
{
if(xin[i]!=xin[len2-i-1])
ok=0;
}
if(ok)
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}
return 0;
}
第七题://瞟的
#include<stdio.h>
#include<string.h>
int main()
{
char str[1100],ch;
int t,k,i;
scanf("%d\n",&t);
while(t--)
{
gets(str);
k=strlen(str);
for(i=0;i<k;i++)
{
if(str[i]!='-')
printf("%c",str[i]);
else
{
if( (str[i-1]>='0' && str[i-1]<='9') && (str[i+1]>='0' && str[i+1]<='9') && (str[i-1]<=str[i+1]) )
{
ch=str[i-1]+1;
while(ch<str[i+1])
{
printf("%c",ch);
ch++;
}
}
else if( (str[i-1]>='A' && str[i-1]<='Z') && (str[i+1]>='A' && str[i+1]<='Z') && (str[i-1]<=str[i+1]) )
{
ch=str[i-1]+1;
while(ch<str[i+1])
{
printf("%c",ch);
ch++;
}
}
else if( (str[i-1]>='a' && str[i-1]<='z') && (str[i+1]>='a' && str[i+1]<='z') && (str[i-1]<=str[i+1]) )
{
ch=str[i-1]+1;
while(ch<str[i+1])
{
printf("%c",ch);
ch++;
}
}
else printf("-");
}
}
printf("\n");
}
return 0;
}