ACM-the mixed letter
来源:互联网 发布:淘宝培训班有用吗 编辑:程序博客网 时间:2024/05/15 11:51
Mike is very upset that many people on the Internet usually mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' case in every word so that it either only consisted of lowercase letters or only consisted of uppercase ones. And he wants to change as few letters as possible in the word.
For example, the word "HoUse" must be changed to "house", and the word "ViP", to "VIP".
If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, "maTRIx" should be changed to "matrix".
You task is to use the given method to change the given word.
Input
The first line contains a single integer n (n<=30), indicating the number of test cases.
Then following n lines, each line contains a word s, it consists of uppercase and lowercase
Latin letters and its length is between 1 and 100, inclusive.
Output
Sample Input
3HoUseViPmaTRIx
Sample Output
houseVIPmatrix
HINT
#include <iostream>
using namespace std;
void lowercase(char*ch,int m);
void uppercase(char*ch,int m);
int main()
{
int n;
char ch[100];
cin>>n;
while(n--)
{
int m=0,s1=0,s2=0;
cin>>ch;
while(ch[m]!='\0')
{
if(ch[m]>='a'&&ch[m]<='z')
s1++;
else if(ch[m]>='A'&&ch[m]<='Z')
s2++;
m++;
}
if(s1>=s2)
lowercase(ch,m);
else
uppercase(ch,m);
}
return 0;
}
void lowercase(char*ch,int m)
{
for(int i=0; i<m; i++)
{
if(ch[i]>='A'&&ch[i]<='Z')
ch[i]+=32;
}
cout<<ch<<endl;
}
void uppercase(char*ch,int m)
{
for(int i=0; i<m; i++)
if(ch[i]>='a'&&ch[i]<='z')
ch[i]-=32;
cout<<ch<<endl;
}
- ACM-the mixed letter
- YTUOJ-The mixed letters
- the mixed letters
- Letter to the Sky
- replacing the letter
- Find the missing letter
- hackerrank The Love-Letter Mystery
- checkio-the most wanted letter
- CheckIO The Most Wanted Letter
- a letter to the editor
- 浙大ACM 3455 Shizuka's Letter
- HDU ACM 1591 Encoded Love-letter
- ACM-a letter and a number
- Mixed-Version OpenVMS Cluster and the Cluster Protocol Version
- object.c c++ mixed code and it support the stl
- The mixed programming in terms of matlab and C++
- sicily 1155 Can I Post the letter
- Sicily 1155 Can I Post the letter
- 用 Redis 实现锁功能
- Node.js学习文档
- 算法竞赛入门经典第二章习题解答
- 一个异常处理的习题(是用RunTimeException还是Exception)
- 算法训练 区间k大数查询
- ACM-the mixed letter
- 4月4日毕设日记
- 我的java学习笔记(17)关于内部类(part 2)
- ASP打印指定GridView内容
- 2015阿里巴巴前端实习生在线笔试题
- Minimum Path Sum -- leetcode
- 广度优先搜索和深度优先搜索
- Qt更改icon颜色
- 需求:查询某个字段在数据库中是否存在记录,如果存在,则更新这条记录;如果不存在,则增加这条记录