- /* <Merry Christmas> **
- ** input:The input consists of multiple test cases. Each test case consists of two positive intergers m,n. **
- ** And m means the height of the triangle, n means the length of the trunk. **
- ** **
- ** output:The picture of the tree like the sample shows. You shouldn't add any extra blanks after each line,**
- *************************************************************************************************************/
- //code begin
- #include <iostream>
- #include <string>
- using namespace std;
- int main()
- {
- int i_height,i_trunk,length,i,j,m,n;
- string input;
- while(1)
- {
- getline(cin,input);
- const char*pstr = input.c_str();
- i_height = *(pstr)-48;
- i_trunk = *(pstr+2)-48;
- if(i_height == 0||i_trunk == 0) break;//there is 0 in input,then end the while.
- length = i_height;
- //output the triangle
- for(i = 1;i <= i_height;i++)
- {
- for(j = 0;j < length;j++)
- {
- if(j < length-2*i+1)
- cout<<" ";
- else
- cout<<".";
- }
- cout<<endl;
- length++;
- }
- //output the trunk
- for(m = 0;m < i_trunk;m++)
- { for(n = 0;n < i_height-1;n++)
- cout<<" ";
- cout<<"|"<<endl;
- }
- }
- return 0;
- }
Merry Christmas
最新推荐文章于 2024-12-25 14:36:12 发布