寒假集训作业(4)——字符串

http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=1916

#include<stdio.h>
#include<string.h>
#include<iostream>
using namespace std;
int main()
{
    char str[1100],ch;
    int t,k,i;
    cin>>t;
    while(t--)
    {
        cin>>str;
        for(i=0;i<strlen(str);i++)
        {
            if(str[i]!='-') cout<<str[i];//out put as disired...
            else//str[i]=='-'
            {
                if((str[i-1]>='0'&&str[i-1]<='9')&&(str[i+1]>='0'&&str[i+1]<='9')&&(str[i-1]<=str[i+1]))//digit,left one and right one is also digit and left<right...
                {
                    ch=str[i-1]+1;//ascii+1 from left one to the right one
                    while(ch<str[i+1])
                    {
                        cout<<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]))//upper alphabet...
                {
                    ch=str[i-1]+1;
                    while(ch<str[i+1])
                    {
                        cout<<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]))//lower alphabet
                {
                    ch=str[i-1]+1;
                    while(ch<str[i+1])
                    {
                        cout<<ch;
                        ch++;
                    }
                }
                else cout<<"-";
            }
        }
        cout<<endl;
    }
}
但凡满足“-”左右且左小于右的情况,一律循环输出。(进栈)


http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=1334

#include "iostream"
#include "cstring"
using namespace std;
void insertsort(char unsorted[11][20],int *a)
{


    int i,j,p;
    char key[20];
    for(j=1;j<=9;j++)
    {
        strcpy(key,unsorted[j]);
        p=*(a+j);
        i=j-1;
        while(i>=0&&strcmp(unsorted[i],key)>0)
        {
            strcpy(unsorted[i+1],unsorted[i]);
            *(a+i+1)=*(a+i);
            i--;
        }
        strcpy(unsorted[i+1],key);
        *(a+i+1)=p;
    }
}
int main()
{
    char name[11][20];
    int *p;
    int score[11];
    p=score;
    for(int i=0;i<=9;i++)
    {
        cin>>name[i];
    }
    for(int i=0;i<=9;i++)
    {
        cin>>score[i];
    }
    insertsort(name,p);
    for(int i=0;i<=9;i++)
    {
        cout<<name[i]<<","<<score[i]<<endl;
    }
}

采用插入排序法写的,注意点为:分数数组的下标要和名字数组的下表变化一致,而不能再列一个排序。方法详见“插入排序”。


http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2560

#include "iostream"
#include "cstdio"
#include "cstring"
using namespace std;
int fun(char s[])
{
    int b,i,t;
    char a[100010];
    b=strlen(s);
    t=b;
    i=0;
    while(i!=t)
    {
        a[i]=s[b-1];
        b--;
        i++;
    }
    a[i]='\0';
    if(!strcmp(s,a))
    return 1;
    else
    return 0;
}
int main()
{
    char a[100010];
    char temp[100010];
    while(gets(a))
    {
        if(strcmp(a,"2013")==0) break;
        for(int i=0,j=0;i<=100010,j<=100010;i++)
        {
            if(a[i]!=' ') temp[j++]=a[i];
        }
        int i=fun(temp);
        if(i==1) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
}
去除空格并采取函数形式判断回文串。

你可能感兴趣的:(ACM题解报告,集训作业)