1.手机电池余量
描述: 自从有了智能手机,时刻都要关心手机的电量。你的任务很简单,用程序打印符号来表示当前手机的电量。
用10行和10列来表示电池的电量,同时在外围加上边框,每一行表示10%的电量。
假设还有50%的电量,则显示如下:
运行时间限制: 无限制+----------+ |----------| |----------| |----------| |----------| |----------| |++++++++++| |++++++++++| |++++++++++| |++++++++++| |++++++++++| +----------+
内存限制:无限制
输入: 多组测试数据,第一行为测试数据组数N(N<10),紧接着是N行,每行一个数,表示电量,这个数值可能是0,10,20 ,30,40,50,60,70,80,90,100
输出: 每组数据输出一个电池的电量,每组数据之间用15个“=”隔开。
+----------+ |----------| |----------| |----------| |----------| |----------| |++++++++++| |++++++++++| |++++++++++| |++++++++++| |++++++++++| +----------+ =============== +----------+ |----------| |----------| |----------| |----------| |----------| |----------| |----------| |----------| |----------| |----------| +----------+ ===============
#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;
cin >> N;
int a[10];
for(int i = 0; i < N; i ++)
cin >> a[i];
print(N, a);
return 0;
}
2.
姓名的夫妻相
在中国,形容夫妻恩爱的词汇中,大家用的比较多的就是“夫妻相”。所谓“夫妻相”,就是两个人看上去比较般配,长相、身材等某些方面有一定的相似度。本题则另辟蹊径,从人的姓名维度,以字母重复个数来寻找最具“夫妻相”的人。
题目中预先给定一组女士的姓名拼音。输入男士的姓名拼音(拼音中间可以有空格,字母全部小写),依预先给定姓名拼音的先后遍历所有姓名,输出字母重复数最多的女士姓名。
规则1:如果字母重复数最多的女士有多位相同,则以最先匹配的女士做为最具“夫妻相”的人选。
规则2:人名中的相同字母,按重复一次处理。例如:li ling 与li lei 重复的字符个数为2,而不是4。
预置女士名单(先后循序必须保证):
"wang fei",
"zhang man yu",
"zhang zhi yi",
"li li",
"li xiao man",
"li yu cun",
"yang ni",
"xiao tong",
"li lei",
"zhang san"
运行时间限制: 无限制
内存限制: 无限制
输入: 输入一个男士姓名,字符串
输出: 输出最具“夫妻相”的女士姓名
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define N 10
char *womanName[N]={"wang fei",
"zhang man yu",
"zhang zhi yi",
"li li",
"li xiao man",
"li yu cun",
"yang ni",
"xiao tong",
"li lei",
"zhang san"
};
void findMatch(char *woman[], char *man, char *output)
{
int i;
int count =0 ;
int max = 0;
int status = 0;
for (i = 0 ; i < N; i++)
{
char *s = man;
while(*s)
{
char *p = woman[i];
while (*p)
{
if (*s == *p)
{
if (*s != ' ')
{
count++;
}
}
p++;
}
s++;
}
if (count > max)
{
max = count;
status = i;
}
count = 0;
}
strcpy(output, woman[status]);
}
int main()
{
char manName[20];
char match[20] = "";
gets(manName);
findMatch(womanName, manName, match);
printf("%s\n", match);
return 0;
}