Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

又水一道,完全暴力数数

Posted by uncleD at 2019-08-30 09:41:08 on Problem 1496
// 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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator