PAT:1027. 打印沙漏(20) 太复杂


#include<stdio.h> #include<stdlib.h> #include<string.h> #include<algorithm> using namespace std; int main() { int n,other,hang; char p; scanf("%d %c",&n,&p); --n; if(n==0) printf("%c",p); else { hang=1; n/=2; while(n>0) { n-=2*hang+1; ++hang; } } other=-n; for(int i=hang ; i>0 ; --i) { int limit=2*hang+1; for(int k=i ; k<hang ; ++k) printf(" "); for(int j=0 ; j<limit ; ++j) printf("%c",p); printf("\n"); } printf("%d",other); system("pause"); return 0; }


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM