问题A
题目描述
Sumo家的猫非常喜欢滚键盘,每次Sumo开着电脑离开一小会儿,回来的时候都能在屏幕上看到一串神秘代码。今天,Sumo又得到了这么一串神秘代码。当他盯着屏幕上这串东西沉思的时候,突然发现它只包含大小写英文字母,又想到自己的键盘这几天两个Shift键都坏掉了——也就是说只能通过CAPSLOCK键来切换英文大小写了。于是他很好奇,这次滚键盘的过程中,他家的猫至少摁了几次CAPSLOCK键呢?Sumo记得他刚离开的时候,键盘的大写锁定是开的(也就是说输的是大写字母)。
输入描述:
仅包含一个字符串,表示Sumo家的猫摁出的神秘代码。输入保证字符串仅包含大小写英文字母,且长度不超过105。
输出描述:
仅一个整数,表示这次滚键盘的过程中,Sumo家的猫摁CAPSLOCK键的最少次数。
示例1
输入
ZUCCAcmLab
输出
3
示例2
输入
MEOWMEOWMEOWGiveMeCatFoodMEOWMEOWMEOW
输出
8
// A.
#include <bits/stdc++.h>
using namespace std;
char ch[100010];
int main()
{
cin>>ch;
int len=strlen(ch), cnt=0;
for(int i=0;i<len;){
if( ( (ch[i]>='A'&&ch[i]<='Z') && (ch[i+1]>='a'&&ch[i+1]<='z') ) ||( (ch[i]>='a'&&ch[i]<='z') && (ch[i+1]>='A'&&ch[i+1]<='Z') ) ) cnt++,i++;
else i++;
}
if(ch[0]>='a'&&ch[0]<='z') cnt++; //一开始可能是小写字母
cout<<cnt<<endl;
return 0;
}
问题B
输入
2
1
5
10
56 12 1 99 1000 234 33 55 99 812
输出
0.00
291.90
// B.
#include <bits/stdc++.h>
using namespace std;
const int N=1e5+10000;
double a[N];
int t,n;
int main()
{
cin>>t;
while(t--) {
cin>>n;
for(int i=1;i<=n;i++) cin>>a[i];
sort(a+1,a+1+n);
double sum=0,res=0;
for(int i=2;i<=n;i++) {
res+=a[i-1];
sum+=res;
}
printf("%.2lf\n",sum/(n)*1.0);
}
}
问题F
输入
2
1
2
输出
1
4
备注:
In the second sample, Sumo has four situations to drive:
Choose cars with numbers 1 and 2, drive the car with number 1,
Choose cars with numbers 1 and 2, drive the car with number 2,
Choose the car with numbers 1, drive the car with number 1,
Choose the car with numbers 2, drive the car with number 2.
So the answer is 4.
// F.
#include<bits/stdc++.h>
using namespace std;
const int MOD=1e9+7;
typedef long long ll;
int t;
ll n;
ll quick(ll a,ll b)
{
ll res=1;
while(b) {
if(b&1) res=res*a%MOD;
a=a*a%MOD;
b>>=1;
}
return res;
}
int main()
{
cin>>t;
while(t--){
cin>>n;
cout<<n*quick(2,n-1)%MOD<<endl;
}
}
问题L
输入
1
2 1 1
输出
ALL
备注:
In the example, Sumo can flip the coin facing up or down so that all the coins are facing the same way after the first operation.
// L.
#include <iostream>
using namespace std;
int t,n,a,b;
void check(int x,int y,int n){
while(x!=0 && y!=0){
if(x>y){
x=n-1-x;
y=n-x;
}
else{
y=n-1-y;
x=n-y;
}
}
if(x==0) cout<<"DOWN"<<endl;
else cout<<"UP"<<endl;
return;
}
int main(){
cin>>t;
while(t--){
cin>>n>>a>>b;
if(n%2==0) cout<<"ALL"<<endl;
else check(a,b,n);
}
return 0;
}