8 条题解

  • 1
    @ 2023-10-20 22:39:10

    水,切

    #include<bits/stdc++.h>
    using namespace std;
    int main()
    {
    	string s;
    	cin>>s;
    	int sum=0;
    	for (int i=0;i<=s.size()-1;i++)
    		if(s[i]=='1')sum+=1;
    	cout<<sum<<endl;
    	return 0;
    }
    
    • 1
      @ 2022-6-21 1:13:23

      Just split the string at every character '1', and you'll find that the number of the strings you get is one more than the number of the '1's. It's simply done!

      My code, written in CSharp, is as below.

      using System;
      
      namespace HydroOJ.ccf.CSPJ2019A {
          static class ProgramEntry {
              static void Main() {
                  Console.WriteLine(Console.ReadLine().Split('1').Length - 1);
              }
          }
      }
      
      • 1
        @ 2022-6-12 10:19:01

        都是垃圾

        #include<bits/stdc++.h>
        using namespace std;
        long long q,w,e,r,t,y,u,i,o,p,s,d,f,g,h,j,k,l,m,n,v,x,z,kk;
        int b[1000];
        int a[1000];
        int c[1000];
        char cc;
        int main()
        {
        	cin>>n;
        	cout<<n%9;
        	return 0;
        }
        
        • 1
          @ 2022-5-7 22:11:16

          因为长度只有 88 ,所以本蒟蒻直接使用暴力枚举……

          AC代码:

          #include <iostream>
          using namespace std;
          
          int main()
          {
              char k;
              int c=0;
              for(int i=1;i<=8;i++)
              {
                  cin>>k;
                  if(k=='0')continue;
                  c++;
              }
              cout<<c<<endl;
              return 0;
          }
          
          • 1
            @ 2022-3-13 23:57:59

            还算挺简单一道题。直接统计即可。

            #include<bits/stdc++.h>
            using namespace std;
            
            int ans = 0;
            char c;
            
            int main() {
                for(int i = 1; i <= 8; i++) {
                    cin >> ch;
                    if (ch == '1') ans++;
                }
                cout << ans <<endl;
                return 0;
            }
            
            • @ 2023-7-28 9:45:31

              应该是 char ch;

          • 0
            @ 2021-10-10 19:19:45

            charchar 类型数组存储,统计并输出" 11 "的个数即可

            Use an array of char type to count and output the number of "1"

            #include<bits/stdc++.h>
            using namespace std;
            
            int main(){
                int ans=0;
                char a[8];
                for(int i=0;i<8;i++) cin>>a[i];
                for(int i=0;i<8;i++){
            		if(a[i]=='1') ans++;
            	}
                cout<<ans;
                return 0;
            }
            
            • 0
              @ 2021-10-7 13:08:34

              直接输入8个字符,判断即可。

              #include<bits/stdc++.h>
              using namespace std;
              const int N=8;
              char c;
              int ans=0;
              int main()
              {
              	for(int i=1;i<=n;i++)
              	{
              		scanf("%c",&c);
              		if(c=='1')ans++;
              	}
              	printf("%d\n",ans);
              	return 0;
              }
              
              • 0
                @ 2021-10-2 16:21:03

                使用字符串统计 1 的个数即可。

                #include <bits/stdc++.h>
                
                using namespace std;
                
                int ans;
                string s;
                
                int main() {
                    cin >> s;
                    for(auto c : s) {
                        ans += c == '1';
                    }
                    cout << ans << endl;
                    return 0;
                }
                
                • 1

                信息

                ID
                117
                时间
                1000ms
                内存
                256MiB
                难度
                2
                标签
                递交数
                161
                已通过
                98
                上传者