天天看點

SOJ.Concatenation and substring

Concatenation and substring

時間限制:1秒     記憶體限制:256兆 題目描述

In this problem, you are required to concatenate given integers and letters into a string S, and output a substring of S. Note that you need to respectively sort the integers and letters first.

輸入格式

There are multiple cases. For each case, the first line contains two integers n and m (1<=n, m<=100), which denote the number of integers and strings, respectively. Then the second line gives n integers and the third line gives m strings. The fourth line has two integers x and y denoting the starting and ending index of string S for generating the substring.

輸出格式

The substring.

樣例輸入

3 21234 567 89xyz abcd8 9      
樣例輸出
4a      

提示

In the above sample, the string S is “895671234abcdxyz”.

#include<iostream>
#include<string>
#include<algorithm>
#include<sstream>
using namespace std;
int a[1000];
string s[100];
int main()
{
    int n,m;
    while(cin >> n >> m)
    {
        stringstream ss;
        for(int i=0;i<n;i++)
            cin >> a[i];
        for(int i=0;i<m;i++)
            cin >> s[i];
        int x,y;
        cin >> x;
        cin >> y;
        sort(a,a+n);
        sort(s,s+m);
        for(int i=0;i<n;i++) 
            ss << a[i];
        for(int i=0;i<m;i++)
            ss << s[i];
        string str = ss.str();
        string sss = str.substr(x,y-x+1);
        cout << sss << endl;
    }
}