Codeforces 918A Eleven(水的不能在水的打表题)

题目:

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
inputCopy
8
output
OOOoOooO
inputCopy
15
output
OOOoOooOooooOoo

题意:

就是名字叫十一的无聊的小女孩想自己给自己改个名字,她的“mdzz”好朋友说你的名字应该只含有’O’和’o’,并且**当它所在的位数为斐波那契数时为’O’,否则为’o’**给你了一个n代表改完后的名字的长度 (ps:我觉得eleven 好听多了比起这个 作死的小孩)

思路:

直接斐波那契打一个标记表 然后一层for循环判断输出就ojbk

代码:

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <cmath>

using namespace std;
const int N=1e5+10;
int flag[N];//标记数组
int m[N];//斐波那契数组


int main()
{
    ios::sync_with_stdio(false);
    int n;
    m[1]=1;
    m[2]=1;
    flag[1]=1;
    for(int i=3;i<=20;i++)//n小于等于1000 打到20都有点大
        m[i]=m[i-1]+m[i-2],flag[m[i]]=1;
    while(cin>>n)
    {
        for(int i=1;i<=n;i++)//判断输出
        {
            if(flag[i]==1)
                cout<<"O";
            else
                cout<<"o";
        }
        cout<<endl;
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/Puppet__/article/details/79341214