4 条题解

  • 1
    @ 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

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

  • 0
    @ 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; }

    • 0
      @ 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
        标签
        (无)
        递交数
        1524
        已通过
        180
        上传者