#1000 : A + B
描述
求两个整数A+B的和
输入
输入包含多组数据。
每组数据包含两个整数A(1 ≤ A ≤ 100)和B(1 ≤ B ≤ 100)。
输出
对于每组数据输出A+B的和。
1 2 3 4样例输出
3 7
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
int main() {
int x, y;
while(scanf("%d %d", &x, &y)) {
cout<< x+y <<endl;
}
return 0;
}
复制代码
#1051 : 补提交卡
描述
小Ho给自己定了一个宏伟的目标:连续100天每天坚持在hihoCoder上提交一个程序。100天过去了,小Ho查看自己的提交记录发现有N天因为贪玩忘记提交了。于是小Ho软磨硬泡、强忍着小Hi鄙视的眼神从小Hi那里要来M张"补提交卡"。每张"补提交卡"都可以补回一天的提交,将原本没有提交程序的一天变成有提交程序的一天。小Ho想知道通过利用这M张补提交卡,可以使自己的"最长连续提交天数"最多变成多少天。
输入
第一行是一个整数T(1 <= T <= 10),代表测试数据的组数。
每个测试数据第一行是2个整数N和M(0 <= N, M <= 100)。第二行包含N个整数a1, a2, ... aN(1 <= a1 < a2 < ... < aN <= 100),表示第a1, a2, ... aN天小Ho没有提交程序。
输出
对于每组数据,输出通过使用补提交卡小Ho的最长连续提交天数最多变成多少。
3 5 1 34 77 82 83 84 5 2 10 30 55 56 90 5 10 10 30 55 56 90样例输出
76 59 100
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
int main() {
//数据的组数T
int T;
scanf("%d", &T);
int res[T];
for (int i = 0; i < T; i++){
//每组数据输入
int N, M;
scanf("%d %d", &N, &M);
int a[N+2];
// 初始化最前与最后的数据;
a[0] = 0;
a[N+1] = 100;
//屏幕输入需补打卡的日子
for(int j=1;j<N+1;j++){
scanf("%d", &a[j]);
}
//求每组数据替换后的最大间距,a数组长度为N+2;
int maxLen = 0;
for(int temp=0; temp+M+1<N+2; temp++){
int dist = 0;
// 连续a数组中的若干M个元素,才能使得打卡连续天数最大
//所以只需计算数组中M个数据之间的间距
dist = a[temp+M+1] - a[temp] -1;
// 记录补打卡后的最长间距
if(dist > maxLen){
maxLen = dist;
}
}
// 若M>=N,则说明一定能将数据补全
if (M>=N){
maxLen = a[N+1]-a[0];
}
// 保存每组数据补卡后的最大间距
res[i] = maxLen;
}
// 输出补打卡后的最大间距
for(int i = 0; i< T; i++){
printf("%d\n", res[i]);
}
system("pause");
return 0;
}
复制代码
#1082 : 然而沼跃鱼早就看穿了一切
描述
fjxmlhx每天都在被沼跃鱼刷屏,因此他急切的找到了你希望你写一个程序屏蔽所有句子中的沼跃鱼(“marshtomp”,不区分大小写)。为了使句子不缺少成分,统一换成 “fjxmlhx” 。
输入
输入包括多行。
每行是一个字符串,长度不超过200。
一行的末尾与下一行的开头没有关系。
输出
输出包含多行,为输入按照描述中变换的结果。
The Marshtomp has seen it all before. marshTomp is beaten by fjxmlhx! AmarshtompB样例输出
The fjxmlhx has seen it all before. fjxmlhx is beaten by fjxmlhx! AfjxmlhxB
#include<iostream>
#include<stdio.h>
#include<cstring>
using namespace std;
char name[9]={'m','a','r','s','h','t','o','m','p'};
char rep[9]={'f','j','x','m','l','h','x','*','*'};
int main(){
char str[300];//每一行的输入
int s,i,j,len;//定义变量
while(gets(str)){//获取屏幕每行输入
len=strlen(str);//获得输入行的长度
if(len<9){
cout<<str<<endl;
continue;
}
for(s=0;s<=len-9;s++){
int i;
bool flag=true;//默认可匹配成功
for(i=0;i<=8;i++){
// 匹配不成功,则跳出循环
if(str[s+i]!=name[i]&&str[s+i]!=name[i]-32){
flag=false;
break;
}
}
// 匹配成功,则进行字符串替换
if(flag){
for(i=0;i<=8;i++){
str[s+i]=rep[i];
}
}
}
for(i=0;i<len;i++){
if(str[i]!='*')
cout<<str[i];
}
cout<<endl;
}
return 0;
}
复制代码
js中引用方法去实现, 当然算法中是不会这样做的 =_=!
var str = 'The Marshtomp has seen it all before.
var res = ''
marshTomp is beaten by fjxmlhx!AmarshtompB';
res = str.replace(/Marshtomp/gi, 'fjxmlhx')
console.log(res)
复制代码