google compute test Problem C. Moist

google compute test Problem C. Moist

URL:https://code.google.com/codejam/contest/2933486/dashboard#s=p2

#include "stdafx.h"
#include<iostream>
#include<fstream>
#include<vector>
#include<string>
using namespace std;

int insertSort(vector<string> vec)
{
	int count = 0;
	if(vec.size() <= 1)
		return 0;
	for(int i = 1 ;i < vec.size();i++)
	if(vec[i] < vec[i - 1])
	{
		count ++;
		int j = i;
		string str = vec[i];
		while(j >= 1 && vec[j] < vec[j - 1] )
		{
			vec[j] = vec[j -1];
			j --;
		}
		vec[j] = str;
	}
	return count;
}


int main(int argc, char* argv[])
{
	ifstream cin("D:\\in.txt");
	ofstream cout("D:\\out.txt");
	int m,n;
	cin>>m;
	
	string s;
	for(int i = 0 ;i < m ; i ++)
	{
		cin>>n;
		vector<string> vec;
		getline(cin , s);
		for(int j = 1; j <= n;j ++)
		{
			string s;
			getline(cin,s);
			vec.push_back(s);
		}
		cout<<"Case #"<<i+1<<": "<<insertSort(vec)<<endl;
	}
	
	return 0;
}

你可能感兴趣的:(google compute test Problem C. Moist)