字符串 练习

做了一下大一的字符串题 主要是练习一下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;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值