10 条题解

  • 5
    @ 2023-11-7 18:40:46

    呵呵,我想了半天

    #include <bits/stdc++.h>
    using namespace std;
    int main()
    {
        string s;
        while (cin >> s)
        {
            char c = s[0];
            if (c >= 'a' && c <= 'z')
                cout << char(c - 32);
            else
                cout << (char)c;
        }
        return 0;
    }
    
    • 3
      @ 2023-8-20 20:06:46

      c++不会,python来摸鱼👀️

      a = input().split()
      for i in a:
          b = i.capitalize()
          print(b[0],end = "")
      

      已AC

      • 2
        @ 2023-8-5 11:23:59

        因为一个x,卡了我好久

        #include <bits/stdc++.h>
        using namespace std;
        string s;
        char a[15],x;
        int main()
        {
            while(cin>>s)
            {
                if(s[0]>='A'&&s[0]<='Z')
                    a[x]=s[0];
                else
                    a[x]=s[0]-32;
                x++;
            }
            for(int i=0;i<x;i++)
                cout<<a[i];
            return 0;
        }
        
        • 2
          @ 2023-7-7 12:59:39
          #include <iostream>
          #include <string>
          using namespace std;
          int main()
          {
          	string a;
          	getline(cin, a);
          	//这道题虽然看起来难度不大但是稍微有不注意还是很容易WA的,下面提几个容易WA的点
          	//1.空格可以有多个,所以如果找单词首字母采用空格位置+1的话可能下一个位置还是空格,就容易错
          	//2.字母可以大小写,等会给几个我用过的测试案例
          	//3.开头可以有空格,这个是最坑的,因为开头有没有空格并不像后面说单词单词之间一定有空格这么绝对,所以这里我把
          	//  开头有无空格单拎出来进行讨论,而且开头也可以有多个空格
          	//4.测试案例,就用题目给的end of file就可以:
          	/*
                  (开头)end of file
          		(开头)End of File
          		(开头)end             of File
          		(开头)      end         of  File
          	*/
          	int i = 0;
          	while (a[i] == ' ')
          	{
          		i++;
          	}
          	if (a[i] > 90)
          	{
          		a[i] -= 32;
          		cout << a[i];
          	}
          	else
          	{
          		cout << a[i];
          	}
          	for (i; i < a.size(); i++)
          	{
          		if (a[i] == ' ')
          		{
          			if (a[i + 1] == ' ')
          			{
          				continue;
          			}
          			if (a[i + 1] > 90)
          			{
          				a[i + 1] -= 32;
          				cout << a[i + 1];
          			}
          			else
          			{
          				cout << a[i + 1];
          			}
          		}
          	}
          	return 0;
          }
          
          • 2
            @ 2022-12-10 9:33:20

            这道题我做了蛮久的,其实问题不难解决,主要是想不到一个比较好的方法。本题难点在于如何读取字符串,使得后面方便处理。 你会发现我除了用cin读入字符串外,还加了一个getchar函数。因为cin函数遇到空格或者换行会结束读入,但是cin并没有丢弃换行符, 而getchar是可以读取换行符的,因此每次输入一行字符串,用getchar来吸收换行符,判断结束,cin以空格结束,这样可以利用空格切割字符串也是一个讨人喜欢的方法。

            AC代码

            #include <bits/stdc++.h>
            using namespace std;
            int main()
            {
                int n;
                scanf("%d",&n);
                while(n--){
                    string a;
                    while(cin>>a){
                        if(a[0]>='a'&&a[0]<='z'){
                            printf("%c",a[0]-32);
                        }else{
                            printf("%c",a[0]);
                        }
                        char ch=getchar();
                        if(ch=='\n'){
                            break;
                        }
                    }
                    printf("\n");
                }
                return 0;
            }
            
            • @ 2023-2-3 23:33:50

              可以这样做不定输入

              int ctrl_music;
              while(cin>>ctrl_music)
              {...}
              
            • @ 2023-4-22 14:10:10
              #python
              a = input()
              a = a.split()
              b = ''
              for i in a:
              b += i[0]
              print(b.upper())
              
            • @ 2023-6-29 9:40:56

              等一下,nn 是哪来的?

          • 1
            @ 2024-2-21 21:07:12
            #include <bits/stdc++.h>
            using namespace std;
            int main()
            {
            	string s;
                while(cin >> s)
                {
                    if(s[0] >= 'a' && s[0] <= 'z')
                    {
                        char a = s[0] - 32;
                        cout << a;
                    }
                    else
                    {
                        cout << s[0];
                    }
                }
                return 0;
            }
            
            • 1
              @ 2023-10-5 20:23:12
              #include<bits/stdc++.h>
              using namespace std;
              string q,s[10005];
              int n;
              int main()
              {
                  while(cin>>q)
                  {
                      n++;
                      s[n]=q;
                      if(s[n][0]>='A'&&s[n][0]<='Z')
                      {
                          cout<<s[n][0];            
                      }
                      else
                      {
                          char a=s[n][0]-32;
                          cout<<a;
                      }
                  }
                  return 0;
              }
              
              • 1
                @ 2023-6-29 9:46:38

                很多人觉得输入字符串是难点,实际上非常简单:

                #include <bits/stdc++.h>
                using namespace std;
                string s;
                int main(){
                    while (cin>>s){
                        cout<<(char)toupper(s[0]);//注意toupper返回的是int
                    }
                    return 0;
                }
                

                番外:其他缩写

                WA:Wonderful Answer Wrong Answer

                TLE:Time Limit Exceeded(不要一看到 E 就想到 Error)

                MLE:Memory Limit Exceeded

                CE:Compile Error

                RE:Runtime Error

                WWW(万维网):World Wide Web

                • 1
                  @ 2023-4-22 14:09:27
                  #python
                  a = input()
                  a = a.split()
                  b = ''
                  for i in a:
                      b += i[0]
                  print(b.upper())
                  
                  • -2
                    @ 2023-2-15 17:26:45

                    鼓励大家写题解,但注意题解格式。

                    给代码两端加上这个会舒服一些

                    ```cpp

                    你的代码

                    ```

                    这个点在键盘的左上角tab上面那个键,注意切换输入法

                    #include<iostream>
                    using namespace std;
                    int main()
                    {
                        int n;
                        cin>>n;//这是一个注释
                        return 0;
                    }
                    

                    请注意严禁抄袭题解,写题解不要只放代码,需加上你的思路或代码注释。

                    抄袭题解一经发现直接取消成绩。

                    • 1

                    信息

                    ID
                    51
                    时间
                    1000ms
                    内存
                    16MiB
                    难度
                    4
                    标签
                    递交数
                    185
                    已通过
                    88
                    上传者