UVA 417 - Word Index
2012-10-25 13:18
393 查看
题目大意:a=1,b=2……z=26,ab=27……,前面的字母一定会比后面大,比如ab,ac,不能是ca等
思路分析:数据很小最大只到VWXYZ,可以暴力,第一次用map
AC code:
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<map>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
map<string,int> word;
int cnt=1;
char temp[6];
for(char i=\'a\'; i<=\'z\'; i++)
{
temp[0]=i;
word[(string)temp]=cnt++;
}
for(char i=\'a\'; i<=\'y\'; i++)
{
temp[0]=i;
for(char j=i+1; j<=\'z\'; j++)
{
temp[1]=j,temp[2]=\'\\0\';
word[(string)temp]=cnt++;
}
}
for(char i=\'a\'; i<=\'x\'; i++)
{
temp[0]=i;
for(char j=i+1; j<=\'y\'; j++)
{
temp[1]=j;
for(char k=j+1; k<=\'z\'; k++)
{
temp[2]=k,temp[3]=\'\\0\';
word[(string)temp]=cnt++;
}
}
}
for(char i=\'a\'; i<=\'w\'; i++)
{
temp[0]=i;
for(char j=i+1; j<=\'x\'; j++)
{
temp[1]=j;
for(char k=j+1; k<=\'y\'; k++)
{
temp[2]=k;
for(char l=k+1; l<=\'z\'; l++)
{
temp[3]=l,temp[4]=\'\\0\';
word[(string)temp]=cnt++;
}
}
}
}
for(char i=\'a\'; i<=\'v\'; i++)
{
temp[0]=i;
for(char j=i+1; j<=\'w\'; j++)
{
temp[1]=j;
for(char k=j+1; k<=\'x\'; k++)
{
temp[2]=k;
for(char l=k+1; l<=\'y\'; l++)
{
temp[3]=l;
for(int m=l+1; m<=\'z\'; m++)
{
temp[4]=m,temp[5]=\'\\0\';
word[(string)temp]=cnt++;
}
}
}
}
}
string s;
while(cin>>s)
cout<<word[s]<<endl;
return 0;
}
思路分析:数据很小最大只到VWXYZ,可以暴力,第一次用map
AC code:
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<map>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
map<string,int> word;
int cnt=1;
char temp[6];
for(char i=\'a\'; i<=\'z\'; i++)
{
temp[0]=i;
word[(string)temp]=cnt++;
}
for(char i=\'a\'; i<=\'y\'; i++)
{
temp[0]=i;
for(char j=i+1; j<=\'z\'; j++)
{
temp[1]=j,temp[2]=\'\\0\';
word[(string)temp]=cnt++;
}
}
for(char i=\'a\'; i<=\'x\'; i++)
{
temp[0]=i;
for(char j=i+1; j<=\'y\'; j++)
{
temp[1]=j;
for(char k=j+1; k<=\'z\'; k++)
{
temp[2]=k,temp[3]=\'\\0\';
word[(string)temp]=cnt++;
}
}
}
for(char i=\'a\'; i<=\'w\'; i++)
{
temp[0]=i;
for(char j=i+1; j<=\'x\'; j++)
{
temp[1]=j;
for(char k=j+1; k<=\'y\'; k++)
{
temp[2]=k;
for(char l=k+1; l<=\'z\'; l++)
{
temp[3]=l,temp[4]=\'\\0\';
word[(string)temp]=cnt++;
}
}
}
}
for(char i=\'a\'; i<=\'v\'; i++)
{
temp[0]=i;
for(char j=i+1; j<=\'w\'; j++)
{
temp[1]=j;
for(char k=j+1; k<=\'x\'; k++)
{
temp[2]=k;
for(char l=k+1; l<=\'y\'; l++)
{
temp[3]=l;
for(int m=l+1; m<=\'z\'; m++)
{
temp[4]=m,temp[5]=\'\\0\';
word[(string)temp]=cnt++;
}
}
}
}
}
string s;
while(cin>>s)
cout<<word[s]<<endl;
return 0;
}
相关文章推荐
- UVa 417 - Word Index
- [uva-417] Word Index (BFS、队列
- Uva 417 - Word Index
- UVa 417-Word Index
- UVA 417 Word Index
- Uva 417 - Word Index 解题报告(组合数)
- UVA 417 Word Index
- UVA 417 - Word Index(数论)
- uva 417 - Word Index(数位dp)
- UVa 417 Word Index
- uva 517 - Word(暴力+周期)
- uva 1401 - Remember the Word(DP+Tire树,5级)
- UVALive 3942 Remember the word 字典树 动态规划
- uva 1401 - Remember the Word(字典树+dp)
- UVA 159 Word Crosses
- Uva 642 - Word Amalgamation sort qsort
- UVa 1401 Remember the Word
- UVA 12543 Longest Word 解题报告
- Uva 422 - Word-Search Wonder
- POJ 题目1496 Word Index(排列组合)