首页 > 代码库 > codevs——1276 图标缩放
codevs——1276 图标缩放
1276 图标缩放
2012年CCC加拿大高中生信息学奥赛
You have been asked to take a small icon that appears on the screen of a smart telephone and scale it up so it looks bigger on a regular computer screen.
你被要求把手机上的小图标变成电脑上的大的。
The icon will be encoded as characters (x and *) in a 3 × 3 grid as follows:
小图标是:
*x*
xx
* *
Write a program that accepts a positive integer scaling factor and outputs the scaled icon. A scaling factor of k means that each character is replaced by a k × k grid consisting only of that character.
写一个程序把它每一个字符都变成k*k的
The input will be a positive integer k such that k < 25.
输入会是一个正整数k,k<25。
The output will be 3k lines, which represent each individual line scaled by a factor of k and repeated k times. A line is scaled by a factor of k by replacing each character in the line with k copies of the character.
输出会是3k行,详见样例。
3
***xxx***
***xxx***
***xxx***
xxxxxx
xxxxxx
xxxxxx
*** ***
*** ***
*** ***
按照题目要求的缩进
水!
代码
#include<cstdio>#include<cstdlib>#include<cstring>#include<iostream>using namespace std;int n;int read(){ int x=0,f=1; char ch=getchar(); while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘) f=-1; ch=getchar();} while(ch>=‘0‘&&ch<=‘9‘){x=x*10+ch-‘0‘; ch=getchar();} return x*f;}int main(){ n=read(); for(int i=1;i<=n;i++) { for(int j=1;j<=n;j++) cout<<"*"; for(int i=1;i<=n;i++) cout<<"x"; for(int i=1;i<=n;i++) cout<<"*"; cout<<endl; } for(int i=1;i<=n;i++) { for(int j=1;j<=n;j++) cout<<" "; for(int i=1;i<=n;i++) cout<<"x"; for(int i=1;i<=n;i++) cout<<"x"; cout<<endl; } for(int i=1;i<=n;i++) { for(int j=1;j<=n;j++) cout<<"*"; for(int i=1;i<=n;i++) cout<<" "; for(int i=1;i<=n;i++) cout<<"*"; cout<<endl; } return 0;}
codevs——1276 图标缩放