首页 > 代码库 > uva1605 - Building for UN(构造法)

uva1605 - Building for UN(构造法)

这道题构造出的结果很妙,考察思维能力。就两层,每层都n*n个格子,第一层第i行都放国家i,第二层第j列都放国家j。

需要注意的是ASCII中A至Z在a至z的前面(数字小),而且它们两组不挨着。所以需要char c(int i)这个函数。

#include<iostream>#include<cstdio>#include<cstdlib>#include<cstring>#include<cmath>#include<map>#include<set>#include<vector>#include<algorithm>#include<stack>#include<queue>#include<cctype>#include<sstream>using namespace std;#define INF 1000000000#define eps 1e-8#define pii pair<int,int>#define LL long long int#define maxn 100010int n;char c(int i){    if(i<26) return A+i;    else return a+i-26;}int main(){    //freopen("in8.txt","r",stdin);    //freopen("out.txt","w",stdout);    int t=0;    while(~scanf("%d",&n))    {        if(t)        {            printf("\n");        }        else t=1;        printf("2 %d %d\n",n,n);        for(int i=0;i<n;i++)        {            for(int j=0;j<n;j++)            {                printf("%c",c(i));            }            printf("\n");        }        printf("\n");        for(int i=0;i<n;i++)        {            for(int j=0;j<n;j++)            {                printf("%c",c(j));            }            printf("\n");        }    }    //fclose(stdin);    //fclose(stdout);    return 0;}

 

uva1605 - Building for UN(构造法)