ACM省选赛 1001 J2J Encryption

John and Jack are good friends, and both of them like adventures, but their parents do not want them to make troubles here and there, after their making numerous times of troubles, their parents had to forbid the frequency of their meetings. They could only tell each other the time and place of next adventure through letters.
Of course, sometimes, they just write graffiti, to confuse their parents who were in deep curiosity.

To stop their parents from being aware of the contents of their letters, clever John and Jack invented an encryption rule that belongs only to them: J2J Encryption.

The J2J Encryption was as follows:

Only three types of characters--uppercase, lowercase letters and numbers could appear in their character string, and the number of characters in the string should be less than 100.

If one had to put I at the ith position of the string, then put it at the nearest position that was after I and had the same character with it. The last one of each type should be put at the first position of the same type of the character string. If there was only one character in a tyre, no change would be needed.

For example: If there were only three lowercase letters a,b and c in the character string, and they were at the second, forth and sixth position, when encrypted, a was at the forth position, b at the sixth, and c at the second.

Uppercase letters and numbers were under the same encryption rule.

John had written the letter to Jack, now please encrypt it.

Input
First line is an integer n indicate there are n test cases, then n line strings followed.

Output
Output the encrypted string.

Sample input

3
a1W
abc
12a2bRcX

Sample output

a1W
cab
21c2aXbR
郁闷就差一题晋级^^^^^
回来还是写了一下
#include "iostream"
#include <ctype.h>
#include "string"
using namespace std;
char*cstr=NULL;
char*cstrNum=NULL;
char*cstrLow=NULL;
char*cstrUpp=NULL;
void Move(string s,char *ctemp)
{
 
 cstr=ctemp;
 strcpy(cstr,s.c_str());
 char ch=cstr[s.length()];
 for (int i=s.length()-1;i>=0;i--)
 {
  cstr[i+1]=cstr[i];
 }
 cstr[0]=cstr[s.length()];
 cstr[s.length()]='/0';
 
}

void main()
{
 int n,i;
 cin>>n;
 for (i=0;i<n;i++)
 {
  string str,strNum,strLow,strUpp;
  char*c = new char[str.length() + 1];
  cin>>str;
  // c=*(str.c_str());
  strcpy(c,str.c_str());
  for (int j=0;j<str.length();j++)
  {
   if (isdigit(c[j]))
   {
    strNum+=c[j];
    
   }
   if (islower(c[j]))
   {
    strLow+=c[j];
    
   }
   if (isupper(c[j]))
   {
    strUpp+=c[j];
   
   }
   
  }
  int coutNum=0,coutLow=0,coutUpp=0;
  cstrNum = new char[str.length() + 1];
  
  cstrLow = new char[str.length() + 1];
  cstrUpp = new char[str.length() + 1];
  Move(strNum,cstrNum);
  Move(strLow,cstrLow);
  Move(strUpp,cstrUpp);
  for (j=0;j<str.length();j++)
  {
   if (isdigit(c[j]))
   {
    cout<<cstrNum[coutNum];
    coutNum++;
   }
   if (islower(c[j]))
   {
    cout<<cstrLow[coutLow];
    coutLow++;
    
   }
   if (isupper(c[j]))
   {
     cout<<cstrUpp[coutUpp];
    coutUpp++;
    
   }
   
  }
  cout<<endl;
 }
 delete[]cstrNum;
 delete[]cstrLow;
 delete[]cstrUpp;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值