http://acm.zjut.edu.cn/ShowProblem.aspx?ShowID=1673
Description: 楠哥哥是个小屁孩,喜欢玩筷子。有天他发现若干根筷子可以搭成一些数字。如图: (搭出数字1需要两个筷子,数字2需要5根筷子……) 现在就有疑问了,给定n(2<=n<100)根筷子,那个可以组成的最大数是多少? Input: 每行给定一个筷子数量n (2<=n<100) Output: 每行输出用这n根筷子所能组成的最大数字 Sample Input: 3 6 7 15 Sample Output: 7 111 711 7111111 #include<iostream> #include<iostream> #include<string> #include<cstring> using namespace std; int chop[10]; int main() { int n; while(cin>>n) { if(n%2) { cout<<7<<string(n/2-1,'1')<<endl; } else { cout<<string(n/2,'1')<<endl; } } }