题目链接:
http://acm.hdu.edu.cn/showproblem.php?pid=4706
解题思路:
直接模拟就好了。。。
简单的水题。可是我模拟太烂了,没办法,比赛时,为了题数,只好暴力求解了...
AC代码:
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
printf("a e\n");
printf("bdf\n");
printf("c g\n");
printf("h n\n");
printf("i mo\n");
printf("jl p\n");
printf("k q\n");
printf("r z\n");
printf("s ya\n");
printf("t x b\n");
printf("uw c\n");
printf("v d\n");
printf("e o\n");
printf("f np\n");
printf("g m q\n");
printf("h l r\n");
printf("ik s\n");
printf("j t\n");
printf("u g\n");
printf("v fh\n");
printf("w e i\n");
printf("x d j\n");
printf("y c k\n");
printf("zb l\n");
printf("a m\n");
printf("n b\n");
printf("o ac\n");
printf("p z d\n");
printf("q y e\n");
printf("r x f\n");
printf("s w g\n");
printf("tv h\n");
printf("u i\n");
printf("j z\n");
printf("k ya\n");
printf("l x b\n");
printf("m w c\n");
printf("n v d\n");
printf("o u e\n");
printf("p t f\n");
printf("qs g\n");
printf("r h\n");
printf("i a\n");
printf("j zb\n");
printf("k y c\n");
printf("l x d\n");
printf("m w e\n");
printf("n v f\n");
printf("o u g\n");
printf("p t h\n");
printf("qs i\n");
printf("r j\n");
return 0;
}
另附两大牛AC代码:
#include <iostream>
#include <cstdio>
using namespace std;
char str[100][100];
int main(){
int cnt = 0;
for(int i = 3;i <= 10;i++){
for(int j = 0;j < i;j++){
for(int k = 0;k < i;k++)
str[j][k] = ' ';
str[j][i] = 0;
}
for(int j = 0;j < i;j++){
str[j][0] = 'a' + cnt;
cnt = (cnt+1)%26;
}
for(int j = i-2;j > 0;j--){
str[j][i-1-j] = 'a' + cnt;
cnt = (cnt+1)%26;
}
for(int j = 0;j < i;j++){
str[j][i-1] = 'a' + cnt;
cnt = (cnt+1)%26;
}
for(int j = 0;j < i;j++)
printf("%s\n",str[j]);
}
return 0;
}
#include <stdio.h>
const int N = 26;
int solve(int n, int c){
int dist = 2 * (n - 1);
for (int i = 0; i < n; i++){
for (int j = 0; j < n; j++){
if (j == 0)
printf("%c", 'a' + (c + i) % N);
else if(j == n - 1)
printf("%c", 'a' + (c + i + dist) % N);
else if(i + j == n - 1)
printf("%c", 'a' + (i + c + (n - i - 1) * 2) % N);
else
printf(" ");
}
printf("\n");
}
}
int main(){
int t = 0;
for (int i = 3; i <= 10; i++){
solve(i, t);
t += i * 3 - 2;
}
return 0;
}