码迷,mamicode.com
首页 > 其他好文 > 详细

uva1605 - Building for UN(构造法)

时间:2014-10-25 22:49:30      阅读:213      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   io   os   ar   for   sp   div   

这道题构造出的结果很妙,考察思维能力。就两层,每层都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 100010
int 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(构造法)

标签:style   blog   color   io   os   ar   for   sp   div   

原文地址:http://www.cnblogs.com/zywscq/p/4050974.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!