2 solutions

  • 1
    @ 2026-4-1 9:47:58
    #include<bits/stdc++.h>
    using namespace std;
    string s[111110];
    int main()
    {
        int t;cin>>t;
        while(t--)
        {
            int n;cin>>n;
            for(int i=1;i<=n;i++)
            {
                cin>>s[i];
            }
            sort(s+1,s+n+1);
            bool st=true;
            for(int i=1;i<=n;i++)
            {
                for(int j=0;j+1<s[i].size();j++)
                {
                    if(s[i][j]>s[i][j+1]) 
                    {
                        st=false;
                    }
                }
            }
            for(int i=1;i+1<=n;i++)
            {
                if(s[i][s[i].size()-1]>s[i+1][0]) st=false;
            }
            if(st==true) cout<<1<<endl;
            else cout<<0<<endl;
        }
        return 0;
    }
    
    • 0
      @ 2026-11-11 20:57:33
      #include<bits/stdc++.h>
      using namespace std;
      const int N=210;
      string s[N];
      int main()
      {
      	int t;
      	cin>>t;
      	while(t--)
      	{
      		int n;
      		cin>>n;
      		for(int i=1;i<=n;i++)
      		{
      			cin>>s[i];
      		}
      		sort(s+1,s+n+1);
      		bool st=true;
      		string s1; 
      		for(int i=1;i<=n;i++)
      		{
      			s1=s1+s[i];
      		}
      		for(int i=0;i+1<s1.size();i++)
      		{
      			if(s1[i]>s1[i+1]) st=false;
      		}
      		if(st) cout<<1<<endl;
      		else cout<<0<<endl;
      	}
      	return 0; 
      } 
      
      • 1

      Information

      ID
      2216
      Time
      1000ms
      Memory
      256MiB
      Difficulty
      9
      Tags
      # Submissions
      13
      Accepted
      5
      Uploaded By