C++二级题目4

小白鼠再排队
不会
多余的数

cpp 复制代码
#include<iostream>
#include<string.h>
#include<stdio.h>
#include<iomanip>
#include<cmath>
#include<bits/stdc++.h>
int a[2000][2000];
int b[2000];
char c[2000];
long long n;
using namespace std;
int main()
{
	int h=0;
	int sum=0;
	int s=0;
	for(int i=0;i<11;i++)
	{
		cin>>b[i];
		sum=sum+b[i];
	}
	cin>>h;
	s=sum-h;
	cout<<s;
	return 0;
}

打字员

cpp 复制代码
​
#include<stdio.h>
#include<string.h>
int main()
{
     char sz[255];
	 int sum,n,l,k,w;
	 cin>>w;
	 while(w)
	 {
	 gets(sz);
	 
		 l=strlen(sz);
		 if(sz[0]>=65&&sz[0]<=90)  
         {sum=1+l;
         }
		 else                      
         {sum=0+l;
         }
         n=l-1;
		 while(n>0)
		 {    
            if((sz[n]>=65&&sz[n]<=90)&&(sz[n-1]>=97&&sz[n-1]<=122))  
            {
                sum+=1;
            }
			else if((sz[n-1]>=65&&sz[n-1]<=90)&&(sz[n]>=97&&sz[n]<=122))  
            {sum+=1;
            }
			n--;
		 }
		 
		 printf("%d\n",sum);
	 
	 w--;
	 }
	 return 0;
}

​

最好的草

cpp 复制代码
​
#include <iostream>
char ar[1000][10500];
using namespace std;
int main()
{
    int r, c, an = 0;
	cin >> r >> c;
	for (int i = 0; i < r; i++) {
		for (int j = 0; j < c; j++) {
			cin >> ar[i][j];
			if (ar[i][j] == '#' && ar[i][j + 1] != '#' && ar[i][j - 1] != '#' && ar[i + 1][j]  != '#' && ar[i - 1][j] != '#') {
				an++;
			} 
		}
	} 
	cout << an;
    return 0;
}

​

字符串中最长的连续 出现的字符

cpp 复制代码
#include <iostream>
#include <cstring>
using namespace std;
char a[300];
int main(){

    cin>>a;
    int n=strlen(a);
    int num=1;
    int max=0;
    char maxc;
    for (int i = 0; i < n; i++) {
        if(a[i]==a[i+1]){
            num++;
        } 
        else{
            if(num>max){
                max=num;
                maxc=a[i];
            }
            num=1;
        }
    }
    cout<<maxc<<" "<<max;
}
相关推荐
xlp666hub2 小时前
Leetcode第五题:用C++解决盛最多水的容器问题
linux·c++·leetcode
得物技术3 小时前
搜索 C++ 引擎回归能力建设:从自测到工程化准出|得物技术
c++·后端·测试
xlp666hub1 天前
Leetcode 第三题:用C++解决最长连续序列
c++·leetcode
会员源码网1 天前
构造函数抛出异常:C++对象部分初始化的陷阱与应对策略
c++
xlp666hub1 天前
Leetcode第二题:用 C++ 解决字母异位词分组
c++·leetcode
不想写代码的星星1 天前
static 关键字:从 C 到 C++,一篇文章彻底搞懂它的“七十二变”
c++
xlp666hub2 天前
Leetcode第一题:用C++解决两数之和问题
c++·leetcode
不想写代码的星星2 天前
C++继承、组合、聚合:选错了是屎山,选对了是神器
c++
不想写代码的星星3 天前
std::function 详解:用法、原理与现代 C++ 最佳实践
c++
樱木Plus5 天前
深拷贝(Deep Copy)和浅拷贝(Shallow Copy)
c++