⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 1062.cpp

📁   输入的第一行是一个正整数N(1<=N<=40)
💻 CPP
字号:
#include<iostream>
#include<stdlib.h>
#include<fstream>
#include<sstream>
#include<string>
#include<time.h>
using namespace std;
string a[1001];
string b[1001];
string c[1001];
int n;
bool com(string &a,string &b)
{
    int flag;
    for(int i=0;i<a.size();i++){
      if(a[i]==':'){
         flag=i;  
         break;
      }    
    }
/*    for(int i=0;i<flag;i++){
            a1[i]=a[i];
            b1[i]=b[i];
    }*/
    string a1(a,0,flag),b1(b,0,flag);
    if(atoi(a1.c_str())>atoi(b1.c_str()))
      return true;
    else if(atoi(a1.c_str()) <atoi(b1.c_str()))
         return false;
    else{
        string a2(a,flag+1,a.size());
		string b2(b,flag+1,b.size());
        if(atoi(a2.c_str())>=atoi(b2.c_str()))
          return true;
        else 
            return false;
    }
    
}
int partition(int low, int high) {
		string t1=a[low];
		string t2=b[low];
		string t3=c[low];
		string pivotkey=b[low];
		while(low < high){
			while(low < high && com(b[high],pivotkey)) 
				--high;
			b[low]=b[high];
			a[low]=a[high];
			c[low]=c[high];
			while(low < high && !com(b[low],pivotkey)) 
				++low;
			b[high]=b[low];
			a[high]=a[low];
			c[high]=c[low];
		}
		a[low]=t1;
		b[low]=t2;
		c[low]=t3;
		return low;
}
int randompartition(int low, int high) {
	
		srand((unsigned)time(NULL));
		int i=low+rand()%(high-low+1);
		string j=a[i];
		a[i]=a[low];
		a[low]=j;
		return partition(low,high);
	
}
void sort(int low, int high) {
		if(low < high){
			int pivotloc=partition(low,high);
			sort(low,pivotloc-1);
			sort(pivotloc+1,high);
		}
		
}

int main()
{
    string result,line;
    int sum=1; 
    ifstream in("1061.txt");
    getline(in,line);
    istringstream stream(line);
    stream >> n;
    int i=1;
    while(getline(in,line)){
      istringstream stream(line);
      stream >> a[i];
      stream >> c[i];
      stream >> b[i++];
    }
 /*   cin >>n;
    for(int i=1;i<n+1;i++){
        cin >>a[i];
        cin >>c[i];
        cin >>b[i];    
    }*/ 
    sort(1,n);
    int j=1;
    result=a[1]+" ";
    b[n]="24:60";
    for(int i=2;i<n+1;i++){
          //  cout <<c[i] << " " << b[j] << endl;
            if(com(c[i],b[j])){
                sum++;
                result+=a[i]+" ";   
                j=i;             
            }
    }
    cout << sum << endl;
    string s(result,0,result.size()-1);
    cout << s << endl;
//    system("pause");
    return 0;
}
  /*  ifstream in("1061.txt");
    getline(in,line);
    istringstream stream(line);
    stream >> n;
    int i=0;
    while(getline(in,line)){
      istringstream stream(line);
      stream >> a[i];
      stream >> c[i];
      stream >> b[i++];
    }*/
    /*    for(int i=0;i<n;i++ ){
            cout << a[i] << " " <<c[i] << " " <<  b[i] << endl;
    }*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -