6 条题解

  • 2
    @ 2024-11-15 19:26:04
    #include <stdio.h>
    #include <iostream>
    #include <string.h>
    using namespace std;
    char a[100000],b[100000];
    int main()
    {
    	cin >> a;
    	int len = strlen(a);
    	if(len > 2 && a[len-1] == 'r' && a[len-2] == 'e')
    		a[len-2] = '\0';
    
    	if(len > 2 && a[len-1] == 'y' && a[len-2] == 'l')
    		a[len-2] = '\0';
    
    	if(len > 3 && a[len-1] == 'g' && a[len-2] == 'n'&& a[len-3] == 'i')
    		a[len-3] = '\0';
    	cout << a << endl;
    
    } 
    
    • 2
      @ 2023-9-17 20:01:42
      #include <bits/stdc++.h>
      using namespace std;
      const int N=1e7+10;
      const int INF=0x3f3f3f3f;
      char a[2005];
      int main()
      {
      	cin>>a;
      	int len=strlen(a);
      	if(a[len-1]=='g' && a[len-2]=='n' && a[len-3]=='i')
      	{
      		for(int i=0;i<len-3;i++)
      		{
      			cout<<a[i];
      		}
      	}
      	else if(a[len-1]=='y' && a[len-2]=='l')
      	{
      		for(int i=0;i<len-2;i++)
      		{
      			cout<<a[i];
      		}
      	}
      	else if(a[len-1]=='r' && a[len-2]=='e')
      	{
      		for(int i=0;i<len-2;i++)
      		{
      			cout<<a[i];
      		}
      	}
      	else
      	{
      		for(int i=0;i<len;i++)
      		{
      			cout<<a[i];
      		}
      	}
      }
      
      
      • 1
        @ 2026-3-8 22:35:12

        #include<bits/stdc++.h> using namespace std; char str[40]; int main() { cin >> str; int s = strlen(str); if(str[s - 2] == 'e' && str[s - 1] == 'r') s -= 2; else if(str[s - 2] == 'l' && str[s - 1] == 'y') s -= 2; else if(str[s - 3] == 'i' && str[s - 2] == 'n' && str[s - 1] == 'g') s -= 3; for(int i = 0; i < s; i++) cout << str[i]; return 0; }

        • 1
          @ 2023-4-19 12:31:35

          可以用string.h的substr提取子串,x.substr(a,len);表示提取x从a位置开始,长度最多为 len的子串,如果没有len,则默认到字符串的末尾结束

          本题代码如下:

          #include<iostream>
          #include<string.h>
          using namespace std;
          typedef long long ll;
          const int N=1e9+1;
          const int INF=0x3f3f3f3f;
          string a;
          int main(){
          	cin>>a;
          	int s=a.size();
          	if(2<=s){
          		string x=a.substr(s-2);
          		if(x=="er"||x=="ly")a=a.substr(0,s-2);
          	}
          	if(3<=s){
          		string x=a.substr(s-3);
          		if(x=="ing")a=a.substr(0,s-3);
          	}
          	cout<<a;
          	return 0;
          }
          
          • 1
            @ 2022-2-19 10:58:38
            #include <stdio.h>
            #include <iostream>
            #include <string.h>
            const int N = 2e5 + 10;
            using namespace std;
            int main()
            {
                char a[N];
                cin >> a;
                int len = strlen(a);
                if (len - 3 >= 0 && a[len - 1] == 'g' && a[len - 2] == 'n' && a[len - 3] == 'i' )
                    a[len - 3] = '\0';
                else if (len - 2 >= 0 && a[len - 1] == 'r' && a[len - 2] == 'e'  )
                    a[len - 2] = '\0';
                else if (len - 2 >= 0 && a[len - 1] == 'y' && a[len - 2] == 'l'  )
                    a[len - 2] = '\0';
                cout << a;
            }
            
            • 0
              @ 2024-7-26 9:25:08
              using namespace std;
              int main(){
              	int m;
              	char a[100];
              	cin>>a;
              	m=strlen(a);
              	cin.ignore(); 
              	if((a[m-1]=='r'&&a[m-2]=='e')||(a[m-1]=='y'&&a[m-2]=='l')){
              		for(int i=0;i<m-2;i++){
              			cout<<a[i];
              		}
              	}
              	else if(a[m-1]=='g'&&a[m-2]=='n'&&a[m-3]=='i'){
              		for(int i=0;i<m-3;i++){
              			cout<<a[i];
              		}
              	}
              	else{
              		for(int i=0;i<m;i++){
              				cout<<a[i];
              		}
              	}	 
              		
              	return 0;
              }
              
              • 1

              信息

              ID
              1128
              时间
              1000ms
              内存
              128MiB
              难度
              5
              标签
              递交数
              670
              已通过
              252
              上传者