UVA13107 Royale With Cheese 题解
题目大意
给定一个字符串
题目分析
模拟题。
可以建一个桶来储存一个字符有没有用过。如果没用过,则在将当前最大序号
对于
代码
#include<bits/stdc++.h>
using namespace std;
int st[27];
int change(int x)
{
string s="";
int g=0;
while(x>0)
{
s+=(x%10+'0');
if(s[g]=='2') s[g]='5';
else if(s[g]=='5') s[g]='2';
else if(s[g]=='6') s[g]='9';
else if(s[g]=='9') s[g]='6';
x/=10;
g++;
}
reverse(s.begin(),s.end());
int ans=0;
for(int i=0;s[i];i++)
ans*=10,ans+=(s[i]-'0');
return ans;
}
int main()
{
string s;
while(cin>>s)
{
int g=0;
memset(st,0,sizeof st);
for(int i=0;s[i];i++)
{
if(!st[s[i]-'a'])
{
++g;
st[s[i]-'a']=change(g);
}
cout<<st[s[i]-'a'];
}
cout<<"\n";
}
return 0;
}