cf918 A. Eleven

A. Eleven
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Eleven wants to choose a new name for herself. As a bunch of geeks, her friends suggested an algorithm to choose a name for her. Eleven wants her name to have exactly n characters.

Her friend suggested that her name should only consist of uppercase and lowercase letters 'O'. More precisely, they suggested that the i-th letter of her name should be 'O' (uppercase) if i is a member of Fibonacci sequence, and 'o' (lowercase) otherwise. The letters in the name are numbered from 1 to n. Fibonacci sequence is the sequence f where

  • f1 = 1,
  • f2 = 1,
  • fn = fn - 2 + fn - 1 (n > 2).

As her friends are too young to know what Fibonacci sequence is, they asked you to help Eleven determine her new name.

Input

The first and only line of input contains an integer n (1 ≤ n ≤ 1000).

Output

Print Eleven's new name on the first and only line of output.

Examples
input
8
output
OOOoOooO
input
15
output
OOOoOooOooooOoo


这个是cf918的A题,很简单,就是斐波那契的数列中的数字变成大写的O,其他的变成小写的o。模拟就可以了。

接下来是我写的代码,虽然和大神写的差距很大,但抓住老鼠的就是好猫,哈哈哈哈哈,加油:


#include <iostream>
#include <math.h>
#include <string.h>
#include <algorithm>

using namespace std;
int a[1005];
int c[1005];
char b[1005];
char d[1005];

int main()
{
	int n;
	scanf("%d",&n);
	if(n == 1)
	{
		printf("O");
		return 0;
	}
	if(n == 2)
	{
		printf("OO");
		return 0;
	}
	if(n == 3)
	{
		printf("OOO");
		return 0;
	}
	if(n == 4)
	{
		printf("OOOo");
		return 0;
	}
	if(n == 5)
	{
		printf("OOOoO");
		return 0;
	}
	if(n == 6)
	{
		printf("OOOoOo");
		return 0;
	}
	int y=1,z=1,s=1;
	a[0] = 1;
	a[1] = 1;
	int sum = 0;
	for(int i=2;i<=n;i++)
	{
		a[i] = a[i-1] + a[i-2];
	}
	for(int i=1;i<=n;i++)
	{
		c[y++] = i;
	}
	for(int i=1;i<=n;i++)
	{
		b[z++] = c[i] + '0';
	}
	for(int i=1;i<n-2;i++)
	{
		sum ++;
	}
		for(int i=1;i<=n;i++)
		{
			b[i] = 'o';
		}
		for(int i=1;i<=n;i++)
		{
			for(int j=1;j<=sum;j++)
			{
				if(i == a[j])
				{
					b[i] = 'O';
				}
			}
		}
		for(int i=1;i<=n;i++)
		{
			printf("%c",b[i]);
		}
	return 0;
}
接下来附上叶大神的代码:
#include<iostream>
#include<cstring>


#define MAX 10005
using namespace std;
bool UP[MAX];
int main( )
{
	int fib[MAX] = {1,1};
	int n;
	memset(UP,false,sizeof(UP));
	UP[1] = true;
	for(int i = 2; fib[i - 1] < 1005; i++){
		fib[i] = fib[i - 1] + fib[i - 2];
		//cout << fib[i] << endl;
		UP[fib[i]] = true;
	}
	cin >> n;
	for(int i = 1; i <= n; i++)
		cout << (UP[i] ? 'O' : 'o');
	cout << endl;
}


加油!


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值