您的位置:首页 > 大数据 > 人工智能

TOJ 2805.Prairie dogs III

2016-09-03 19:19 316 查看
题目链接:http://acm.tju.edu.cn/toj/showp2805.html

2805.   Prairie dogs III
Time Limit: 1.0 Seconds   Memory Limit: 65536K
Total Runs: 1016   Accepted Runs: 684

The lovely prairie dogs come to our sight again! The black-tailed prairie dog is a large, burrowing, ground squirrel belonging to a group of four other prairie dog species found only in North America. The black-tailed
prairie dog is the most abundant and widely distributed prairie dog.
We suppose the prairie dogs are perfect architects, and they build their house in the farmland. One day, the black-tailed prairie dogs assemble at the farmland to play a funny game. The prairie dogs stand
in a line with the length of 3order. Each time the middle third of the line of prairie dogs are disappeared. They repeat until none of the prairie dogs next to each other.
For example, if the order is 3, the initial number of prairie dogs(stands by the mark '@') is 27(33 = 27):
@@@@@@@@@@@@@@@@@@@@@@@@@@@

The middle third of prairie dogs are disappeared(replace '@' with space):
@@@@@@@@@         @@@@@@@@@

and disappear the middle third of each piece of the line:
@@@   @@@         @@@   @@@

and again:
@ @   @ @         @ @   @ @

The process stops because none of the remaining prairie dogs next to each other. Only the final result should be displayed.

Input

Each line of input will be a single number between 0 and 10, inclusive, indicating the order. The input stops when EOF(end of file) is reached.

Output

You must output of final result of the line of prairie dogs, followed by a newline. There is no whitespace before or after your output.

Sample Input

0
1
3

Sample Output

@
@ @
@ @   @ @         @ @   @ @

Problem Setter: chhot@TJURocket

Source: TJU
Programming Contest 2007 Preliminary
Submit   List  
 Runs   Forum   Statistics


水题,上代码

#include <stdio.h>
#include <iostream>
#include <cmath>
using namespace std;
string s;
int n;
void dog(int a){
if(s.length()>=(int)pow(3.0,n)){

s+="\0";
//cout<<s<<"haha"<<s.length()<<endl;
return ;
}
if(a==0){
return dog(1);
}
if(a==1){
string t=" ";
for(int i=1;i<s.length();i++)
t+=" ";
s+=t;
return dog(2);
}
if(a==2){
int length=s.length();
for(int i=0;i<length/2;i++)
s+=s[i];
//cout<<p<<"haha"<<s;
return dog(0);
}
}
int main(){
while(~scanf("%d",&n)){
s="@";
dog(0);
cout<<s<<endl;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  toj 水题