每天学习一点编程(9)(用程序打印符号来表示当前手机的电量。)

来源:互联网 发布:windows手动安装flask 编辑:程序博客网 时间:2024/04/28 00:33
手机电池余量
描述: 自从有了智能手机,时刻都要关心手机的电量。你的任务很简单,用程序打印符号来表示当前手机的电量。
用10行和10列来表示电池的电量,同时在外围加上边框,每一行表示10%的电量。
假设还有50%的电量,则显示如下:
+----------+|----------||----------||----------||----------||----------||++++++++++||++++++++++||++++++++++||++++++++++||++++++++++|+----------+
运行时间限制: 无限制
内存限制:无限制
输入: 多组测试数据,第一行为测试数据组数N(N<10),紧接着是N行,每行一个数,表示电量,这个数值可能是0,10,20 ,30,40,50,60,70,80,90,100

输出: 每组数据输出一个电池的电量,每组数据之间用15个“=”隔开。

Sample Input

2500

Sample Output

+----------+|----------||----------||----------||----------||----------||++++++++++||++++++++++||++++++++++||++++++++++||++++++++++|+----------+===============+----------+|----------||----------||----------||----------||----------||----------||----------||----------||----------||----------|+----------+===============
#include <iostream>#include <string>using namespace std;void print(int N, int *num){if(N < 0 || num == NULL)return;string str1 = "+----------+";string str2 = "|----------|";string str3 = "|++++++++++|";string str4 = "===============";for(int i = 0; i < N; i ++){int temp = num[i] / 10;cout << str1 << endl;for(int j = 0; j < 10 - temp; j ++)cout << str2 << endl;for(int k = 0; k < temp; k ++)cout << str3 << endl;cout << str1 << endl;cout << str4 << endl;}}int main(){int N;cout << "please input the number of test data:"<< endl;cin >> N;int a[10];for(int i = 0; i < N; i ++)cin >> a[i];print(N, a);system("pause");return 0;}



0 0