Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
又水一道,完全暴力数数// poj1496.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。 // #include <iostream> #include <stdio.h> #include <string.h> #include <string> using namespace std; bool illegal(string word) { for (int i = 1; i < word.length(); i++) if (word[i] - word[i - 1] <= 0) return true; return false; } int main() { string word; while (cin>>word) { int wLen = word.length(); if (illegal(word)) { cout << 0 << endl; } else if (wLen == 1) { int index = 1; for (int i = int('a'); i<=int('z'); i++) if (i == int(word[0])) { cout << index << endl; break; } else index++; } else if (wLen == 2) { int index = 0; for (int i = int('a'); i <= int('z'); i++) index++; index++; for (int i = int('a'); i <= int('y'); i++) for (int j = i+1; j <= int('z'); j++) if (i==int(word[0]) && j==int(word[1]) ) { cout << index << endl; break; } else index++; } else if (wLen == 3) { int index = 0; for (int i = int('a'); i <= int('z'); i++) index++; for (int i = int('a'); i <= int('y'); i++) for (int j = i + 1; j <= int('z'); j++) index++; index += 1; for(int i=int('a');i<=int('x');i++) for(int j=i+1;j<=int('y');j++) for (int k=j+1; k <= int('z'); k++) if(i==int(word[0]) && j==int(word[1]) && k==int(word[2])) { cout << index << endl; break; } else index++; } else if (wLen == 4) { int index = 0; for (int i = int('a'); i <= int('z'); i++) index++; for (int i = int('a'); i <= int('y'); i++) for (int j = i + 1; j <= int('z'); j++) index++; for (int i = int('a'); i <= int('x'); i++) for (int j = i + 1; j <= int('y'); j++) for (int k = j + 1; k <= int('z'); k++) index++; index += 1; for (int i = int('a'); i <= int('w'); i++) for (int j = i + 1; j <= int('x'); j++) for (int k = j + 1; k <= int('y'); k++) for (int l = k + 1; l <= int('z'); l++) if (i == int(word[0]) && j == int(word[1]) && k == int(word[2]) && l == int(word[3])) { cout << index << endl; break; } else index++; } else if (wLen == 5) { int index = 0; for (int i = int('a'); i <= int('z'); i++) index++; for (int i = int('a'); i <= int('y'); i++) for (int j = i + 1; j <= int('z'); j++) index++; for (int i = int('a'); i <= int('x'); i++) for (int j = i + 1; j <= int('y'); j++) for (int k = j + 1; k <= int('z'); k++) index++; for (int i = int('a'); i <= int('w'); i++) for (int j = i + 1; j <= int('x'); j++) for (int k = j + 1; k <= int('y'); k++) for (int l = k + 1; l <= int('z'); l++) index++; index += 1; for (int i = int('a'); i <= int('v'); i++) for (int j = i + 1; j <= int('w'); j++) for (int k = j + 1; k <= int('x'); k++) for (int l = k + 1; l <= int('y'); l++) for (int m = l + 1; m <= int('z'); m++) if (i == int(word[0]) && j == int(word[1]) && k == int(word[2]) && l == int(word[3]) && m == int(word[4])) { cout << index << endl; break; } else index++; } } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator