7 条题解

  • 3
    @ 2025-10-1 21:16:24

    一定要理解是最外面一层的括号 /(ㄒoㄒ)/~~ eg1. a(aa(aaA)a 就是4 /(ㄒoㄒ)/~~ eg2. a(aa)aaA)a 还是4 /(ㄒoㄒ)/~~

    • 3
      @ 2024-11-18 10:51:08

      #include <stdio.h> #include <string.h> int main() { int n; scanf("%d", &n); while (n--) { char ar[1003]; scanf("%s", ar); int len = strlen(ar); int sum = 0; int a = 0, b = 0; for (int i = 0; i < len; i++) { if (ar[i] == '(') { a = i+1; break; } } for(int j=a;j<len;j++){ if(ar[j]==')'){ b=j; } } for (; a < b; a++) { if (ar[a] >= 97 && ar[a] <= 122) { sum++; } } printf("%d\n", sum); } return 0; }

      • @ 2024-11-18 11:18:22

        是不是很疑惑,自己的代码为什么不通过,直接看一些例子,你差不多就懂了! eg1:sj(sdh(shsh)xh eg2:dhdh(hdh)dhh)sh

        是不是一瞬间就懂了!

      • @ 2024-11-18 11:47:17

        记住,要看的是大括号!!!@

      • @ 2025-11-13 20:24:47

        括号也占字符啊!!!!!!😕 😕 @

    • 1
      @ 2025-10-28 20:54:11
      #include<stdio.h>
      #include<string.h>
      int main(){
      	int n;
      	char str[1010];
      	scanf("%d",&n);
      	while(n--){
      		scanf("%s",str);
      		int len = strlen(str);
      		int ans = 0;
      		int a[1010] = {0};
      		int b[1010] = {0};
      		int x = 0;
      		int y = 0;
      		for(int i = 0;i < len;i++){
              if(str[i] == '('){
              	a[x] = i;
              	x++;
      		}
      		if(str[i] == ')'){
      			b[y] = i;
      			y++;
      		}
      		}
      		for(int i = 0;i <=x;i++){
      			for(int j = a[i] + 1;j < b[i];j++){
      				if(str[j]>='a'&&str[j]<='z'){
      					ans++;
      				}
      			}
      		}
      		printf("%d\n",ans);
      	}
      }//提示说会不出现(fs(hf)adf)这种情况但是没有说不会出现(sdfad)sa)f)这种情况哦👀️ 
      
      • 1
        @ 2025-10-5 18:55:37

        #include<stdio.h>

        #include<string.h>

        int main(){

        int n,m;

        char a[1005];

        scanf("%d",&n);

        while(n--){

        int x=0,y=0;

        int sum=0;

        scanf("%s",a);

        m=strlen(a);

        for(int i=0;i<m;i++){

        if(a[i]=='('){

        x=i;

        break;

        }

        }

        for(int i=0;i<m;i++){

        if(a[i]==')'){

        y=i;

        }

        }

        for(int i=x+1;i<=y-1;i++){

        if(a[i]>='a'&&a[i]<='z'){

        sum++;

        }

        }

        printf("%d\n",sum);

        }

        return 0;

        }

        • 1
          @ 2024-11-6 15:09:20

          #include<stdio.h> #include<string.h> int main() { int n; scanf("%d", &n); while (n--) { char arr[1010]; int num = 0; scanf("%s", arr); int sz = strlen(arr); int a = 0; int total = 0; for (int i = 0; i < sz; i++) { num = 0; if (arr[i] == '(') { for (int j = i + 1; arr[j] != ')'&&j<sz; j++) { if (arr[j] >= 'a' && arr[i] <= 'z') { num++;//记录每一次遇到()里的数目 } if (arr[j+1] == ')') { a = 1;//如果有括回来的括号,接收数据 } else { a = 0; } } } if (a==1) { total += num; } } printf("%d\n", total); } return 0; }

          • 1
            @ 2023-10-13 13:25:04
            #include<stdio.h>
            #include<string.h>
            int main ()
            {
                int n;
                scanf("%d",&n);
               for(int i=1;i<=n;i++)
               {
            	int count=0;
            	char ch[1000];
            	memset(ch,'\0',sizeof(ch));//清空数组
            	scanf("%s",ch);
            	for(int m=0;;m++)
            	{
            		if(ch[m]=='(')//检测左括号
            		{
            			int t=m+1;
            			while(ch[t]!=')')
            			{t++;//记录括号内字符数量
            			if(ch[t]=='\0')
            			break;}
            			if(ch[t]==')')//检测右括号
            				{
            					for(;m<t;m++)
            					{
            						if(ch[m]>='a'&&ch[m]<='z')//检测小写字母
            		  				count++;
            					}
            				}
            				if(ch[t]=='\0')
            				{m=t;//标记跳出点
            				break;}
            		}
            		if(ch[m]=='\0')//跳出循环
            		break;
            	}
            	printf("%d\n",count);
               }
                return 0;
            }
            
            • 0
              @ 2023-10-7 17:39:29
              //仲夏特供
              #include <iostream>
              using namespace std;
              int main() {
                string a;
                int T = 0;
                cin >> T;
                for (int i = 0; i < T; i++) {
                  cin >> a;
                  int length1 = a.length();
                  int biaoJi1 = 0;
                  int biaoJi2 = 0;
                  for (int j = 0; j < length1; j++) {
                    if (a[j] == '(') {
                      biaoJi1 = j;
                      break;
                    }
                  }
                  for (int j = biaoJi1; j < length1; j++) {
                    if (a[j] == ')') {
                      biaoJi2 = j;
                    }
                  }
                  int sum = 0;
                  for (int j = biaoJi1 + 1; j < biaoJi2; j++) {
                    //   cout << a[j] << endl;
                    if ('a' <= a[j] && a[j] <= 'z') {
                      sum++;
                    }
                  }
                  cout << sum << endl;
                }
              }
              
              • 1

              信息

              ID
              211
              时间
              1000ms
              内存
              128MiB
              难度
              8
              标签
              (无)
              递交数
              1671
              已通过
              199
              上传者