Groups
Groups
Sign in
Groups
Groups
星星爱CPP
Conversations
About
Send feedback
Help
单循环打印向中心递增的矩形
1 view
Skip to first unread message
bruc...@gmail.com
unread,
Dec 20, 2007, 1:11:58 AM
12/20/07
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to 星星爱CPP
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cassert>
using namespace std;
void foo( int n )
{
const int LEN = 10;
const char* L = "0123456789";
const char* R = "9876543210";
assert( n>=0 && n<=LEN*2 );
for( int i=0; i<n; ++i )
{
int c = (n-abs(i*2+1-n))/2;
cout.write( L, c )
<< setw(n-2*c) << setfill(L[c]) << ""
<< (R+LEN-c)
<< endl;
}
}
int main( void )
{
foo( 15 );
return 0;
}
Reply all
Reply to author
Forward
0 new messages