# 腾讯暑假实习题和答案

import java.util.*;
public class Main{
public static void main(String[] args){
Scanner scan = new Scanner(System.in);
while(scan.hasNext()){
String str = scan.nextLine();
System.out.println(getResult(str));
}
}
public static String getResult(String str){
char[] c = str.toCharArray();
int k=0;
for(int i=0;i<c.length;i++){
if(String.valueOf(c[i]).matches("[a-z]")){
char temp = c[i];
for(int j=i;j>k;j--){
c[j] = c[j-1];
}
c[k] = temp;
k++;
}
}
String str2 = String.valueOf(c);
return str2;
}

}

2.小Q今天在上厕所时想到了这个问题：有n个数，两两组成二元组，差最小的有多少对呢？差最大呢？

N - 本组测试数据有n个数
a1,a2...an - 需要计算的数据

1<=N<=100000,0<=ai<=INT_MAX.

6

45 12 45 32 5 6

1 2

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main(){

int n;

while (cin>>n) {
vector<int> nums(n);
for (int i=0; i<n; i++) {
cin>>nums[i];
}

int minNum=0, maxNum=0;
sort(nums.begin(), nums.end());

int m1 = 0, m2 = n-1, a=1, b=1;
while (nums[m1+1] == nums[m1]) {
a++;
m1++;
}

while (nums[m2] == nums[m2-1]) {
b++;
m2--;
}
maxNum = a*b;
int minTemp=nums[n-1];
for (int i=1; i<n; i++) {
if (nums[i]-nums[i-1]<minTemp) {
minTemp = nums[i]-nums[i-1];
}
}

if (minTemp >0) {

for (int i=1; i<n; i++) {
if (nums[i]-nums[i-1] == minTemp) {
minNum++;
}
}

}else{

for (int i=1; i<n; i++) {
int j=i-1;
while (nums[j]==nums[i] && j>=0) {
minNum++;
j--;
}
}
}

cout<<minNum<<" "<<maxNum<<endl;

}

return 0;
}

3.

#include <iostream>
#include <string.h>
#include <algorithm>
using namespace std;

const int MAXN=1010;
int temp[MAXN][MAXN];
int getRemoveNumber(string &s1)
{
string s2(s1);
reverse(s2.begin(),s2.end());
int len=s1.length();
memset(temp,0,sizeof temp);
for(int i=0;i<len;++i)
{
for(int j=0;j<len;++j)
{
if(s1[i]==s2[j])
temp[i+1][j+1]=temp[i][j]+1;
else temp[i+1][j+1]=max(temp[i][j+1],temp[i+1][j]);
}
}
return len-temp[len][len];
}

int main()
{
string s;
while(cin>>s)
{
cout<<getRemoveNumber(s)<<endl;
}
return 0;
}