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;
}
相关推荐
星空椰5 小时前
Python 面向对象高级:继承与类定义详解
开发语言·python
wunaiqiezixin5 小时前
如何在C++中创建和管理线程
c++
白露与泡影5 小时前
2026大厂Java面试题大全!牛客网最新版
java·开发语言
凯瑟琳.奥古斯特5 小时前
高阶子查询题目精炼
开发语言·数据库·python·职场和发展·数据库开发
雪度娃娃5 小时前
转向现代C++——在意为改写的函数添加 override
开发语言·c++
王老师青少年编程5 小时前
csp信奥赛C++高频考点专项训练之前缀和&差分 --【一维差分】:[NOIP 2018 提高组] 铺设道路
c++·前缀和·差分·csp·高频考点·信奥赛·铺设道路
星马梦缘5 小时前
aaaaa
数据结构·c++·算法
喵星人工作室6 小时前
C++火影忍者1.1.2
开发语言·c++
basketball6167 小时前
C++ 中的 ptrdiff_t 详解
开发语言·c++
wunaiqiezixin7 小时前
互斥锁与自旋锁的区别
c++