sicily 1027

 #include "iostream"
#include "string"
using namespace std;
int main()
{
 int n;
 while (cin >> n)
 {
  if (n == 0)  break;
  string *str = new string [n];
  for (int i = 0; i < n; i++)//字符串的输入
  {
   if (i == 0)  cin.get();
   getline(cin, str[i]);
  }
  string *str1 = new string [n*2];
  int j = 0;
  for (int i = 0; i < n; i++)//将字符串拆为两部分,前部分为字符,后部分为数字
  {
   j =  i * 2;
   int length = str[i].find(" ");
   for (int m = 0; m < length; m++)
   {
    str1[j].push_back(str[i][m]);
   }
   for (int q = str[i].find(" ")+1; q < str[i].size(); q++)
   {
    str1[j+1].push_back(str[i][q]);
   }
   }
  string *s = new string [n];
  int q = 0;
  for (int m = 1; m < n * 2; m++)//对字符串的比较,对相同的字符串进行整理
     for (int i = m + 2; i < n * 2; i += 2)
      if (str1[m] == str1[i])
      {
       s[q] = str1[i-1];
       s[q+1] = str1[m-1];
       q = q + 2;
      }
    int a, k;
    for (a = 1; a < n; a += 2)//对字符串的比较,然后定最后的排列顺序
     for ( k = a + 2; k < n; k += 2)
     {
      if (s[a] > s[k])
      {
       swap(s[a], s[k]);
       swap(s[a-1], s[k-1]);
      }
     if (k == n-1)
       cout << s[a-1] << " is the MaJia of " << s[a]  << endl;
    }
     cout << s[n-2] << " is the MaJia of " << s[n-1] << endl;
      cout << endl;
 }
}


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值