toj 2975 Encription

2975.   Encription
Time Limit: 1.0 Seconds    Memory Limit: 65536K
Total Runs: 233    Accepted Runs: 88



Now CUET has its own local Area Network and almost all PCs are connected with each other. Often teachers give them very hard program to solve in a minimum time.

Sometimes Its not possible by all to solve those problem. Ultimately they go in the wrong Computer Lab has a software to detect C/C++. It prevents copying C++ programs through Network. But student of CUET are very smart. To avoid the Detective software, first they encode the C/C++ program then they send it to the destination. They always use shifting method (only for 'a' to 'z' and 'A' to 'Z') for encode. That is, they shifts each character by n. I.e. if n = 1 they use 'b' for 'a', 'c' for 'b' and so on. If n = 2 then 'c' for 'a', 'd' for 'b' ... 'a' for 'y' and 'b' for 'z'. It is the same for uppercase letter.

But the n is not defined for encoding.

you are hired to develop a detective program to decode the original program. They only information available for you is that "Letter of highest frequency for a C/C++ program is 'i' ". that is each C/C++ program the letter 'i' is type maximum times. Please note it is case-insensitive when calculating the frequency.

Input

Input will be an encoded C/C++ program.

Output

Your have to print the original C/C++ program.

Sample Input

#jodmvef
Nbjo()
{
Jou j;
j =5;
qsjoug("%e",j);
}

Sample Output

#include
Main()
{
Int i;
i =5;
print("%d",i);
}

Problem Setter: M H Rasel.



Source: CUET Easy Contest
Submit   List    Runs   Forum   Statistics

#include  < iostream >
#include 
< string >
#include 
< map >
#define  MAX 3000
using   namespace  std;
map
< char , int > M;
string  str[MAX];
int  num;
int  main()
{
    
int  kk,len,i,j,maxtemp;
    
char  maxchar;
    kk
= 0 ;
    M.clear();
    maxtemp
=- 1 ;
    
while (getline(cin,str[kk], ' \n ' ))
    {
        len
= str[kk].length();
        
for (i = 0 ;i < len;i ++ )
        {
            
if ((str[kk][i] >= ' a ' && str[kk][i] <= ' z ' ) || (str[kk][i] >= ' A ' && str[kk][i] <= ' Z ' ))
            {
                
if (M[str[kk][i]] == 0 )
                {
                    M[str[kk][i]]
= 1 ;
                    
if (maxtemp < 1 )
                    {
                        maxtemp
= 1 ;
                        maxchar
= str[kk][i];
                    }
                }
                
else
                {
                    M[str[kk][i]]
++ ;
                    
if (maxtemp < M[str[kk][i]])
                    {
                        maxtemp
= M[str[kk][i]];
                        maxchar
= str[kk][i];
                    }
                }
            }
        }
        kk
++ ;
    }
    
int  n = ' i ' - maxchar;
    
if (n > 0 && n >= 26 )
        n
%= 26 ;
    
char  temp;
    
for (i = 0 ;i < kk;i ++ )
    {
        len
= str[i].length();
        
for (j = 0 ;j < len;j ++ )
        {
            
if ((str[i][j] >= ' a ' && str[i][j] <= ' z ' ))
            {
                
if (n > 0 )
                {
                    
for ( int  kkk = 0 ;kkk < n;kkk ++ )
                    {
                        str[i][j]
++ ;
                        
if (str[i][j] > ' z ' )
                            str[i][j]
= ' a ' ;
                    }
                }
                
else
                {
                    temp
= str[i][j] + n;
                    
if (temp < ' a ' )
                    temp
= temp - ' a ' + ' z ' + 1 ;
                    str[i][j]
= temp;
                }
                
            }
            
else   if (str[i][j] >= ' A ' && str[i][j] <= ' Z ' )
            {
                    temp
= str[i][j] + n;
                    
if (temp > ' Z ' )
                    {
                        temp
= temp - ' Z ' + ' A ' - 1 ;
                    }
                    
else   if (temp < ' A ' )
                        temp
= temp - ' A ' + ' Z ' + 1 ;
                    str[i][j]
= temp;
            }
        }
    }
    
for (i = 0 ;i < kk;i ++ )
    {
        cout
<< str[i] << endl;
    }
    
return   0 ;
}

转载于:https://www.cnblogs.com/forever4444/archive/2009/05/19/1460379.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值