把一个二维字符型数组在进行初始化为空格时 char s[100][100]={" "};并未把数组全部初始化为空格而是把第一位初始化为空格。。。。。。
#include<iostream>
#include<algorithm>
#include<string.h>
using namespace std;
int main() {
char s[10][10]= {"1"};
for(int i=0; i<10; i++) {
for(int j=0; j<10; j++)
cout<<s[i][j];
cout<<endl;
}
return 0;
}
碰到一题就因为这样找了好久好久。。。。
HDU - 4706
Today is Children’s Day. Some children ask you to output a big letter ‘N’. ‘N’ is constituted by two vertical linesand one diagonal. Each pixel of this letter is a character orderly. No tail blank is allowed.
For example, this is a big ‘N’ start with ‘a’ and it’s size is 3.
a e
bdf
c g
Your task is to write different ‘N’ from size 3 to size 10. The pixel character used is from ‘a’ to ‘z’ continuously and periodic(‘a’ is reused after ‘z’).
Input
This problem has no input.
Output
Output different ‘N’ from size 3 to size 10. There is no blank line among output.
Sample Output
[pre]
a e
bdf
c g
h n
i mo
jl p
k q
…
r j
[/pre]
Hint
Not all the resultsare listed in the sample. There are just some lines. The ellipsis expresseswhat you should write.
#include<iostream>
#include<string>
#include<string.h>
using namespace std;
int main() {
char c = 'a';
int t = 3;
while (t < 11) {
char s[12][12];
for (int i = 0; i < t; i++)
for (int j = 0; j < t; j++)
s[i][j] = ' ';
s[0][0] = c;
int k = 0;
for (int i = 1; i < t; i++)
{
c = c + 1;
if (c > 'z')
c = c - 26;
s[i][0] = c;
}
for (int i = t - 2; i > 0; i--)
{
c = c + 1;
if (c > 'z')
c = c - 26;
k++;
s[i][k] = c;
}
for (int i = 0; i < t; i++)
{
c = c + 1;
if (c > 'z')
c = c - 26;
s[i][t - 1] = c;
}
for (int i = 0; i < t; i++)
{
for (int j = 0; j < t; j++)
{
printf("%c", s[i][j]);
}
cout << endl;
}
t++;
c = c + 1;
if (c > 'z')
c = 'a';
}
system("pause");
return 0;
}