Merge pull request #2 from KiritoTRw/master

QUST OJ Added.
This commit is contained in:
Kirigaya Kazuto 2016-04-27 18:39:16 +08:00
commit a1e4a6c933
3 changed files with 152 additions and 0 deletions

41
QUSTOJ/1437.cpp Normal file
View File

@ -0,0 +1,41 @@
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;
class pack
{
public:
int real;
int absed;
pack(int a):real(a),absed(abs(a)) {}
};
bool cmp(const pack& a,const pack& b)
{
return a.absed>b.absed;
}
int main()
{
int n;
while(cin>>n)
{
if(n==0) return 0;
vector<pack> bus;
for(int i=0; i<n; i++)
{
int tmp;
cin>>tmp;
bus.push_back(pack(tmp));
}
sort(bus.begin(),bus.end(),cmp);
for(int i=0; i<n-1; i++)
{
cout<<bus.at(i).real<<" ";
}
cout<<bus.at(n-1).real<<" "<<endl;
}
return 0;
}

30
QUSTOJ/1464.cpp Normal file
View File

@ -0,0 +1,30 @@
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;
char a[1024];
char b[1024];
int main()
{
while(gets(a)!=NULL)
{
if(strlen(a)<1)
{
continue;
}
int i=0,j=0;
while(a[i]!=0)
{
if(a[i]!=' ')
{
b[j++]=a[i];
}
++i;
}
b[j]=0;
puts(b);
}
return 0;
}

81
QUSTOJ/1626.cpp Normal file
View File

@ -0,0 +1,81 @@
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;
int data[4];
char buff[32];
char cmdline[10240];
int strlenx(const char* inc)
{
int i=0;
while(inc[i]!='\0') i++;
return i;
}
//Kiritow's Quick sort function : written on Nov. 2ND ,rewritten on Nov. 10TH
//Updated Version : QuickSort (Build 2)
template <class T>
void quicksort(T* a,int left,int right)
{
if(left>=right) return;
T keyvalue=a[left];
int i=left,j=right;
while(i<j)
{
while(i<j&&a[j]>=keyvalue)
{
j--;
}
while(i<j&&a[i]<=keyvalue)
{
i++;
}
T tmp=a[i];
a[i]=a[j];
a[j]=tmp;
}
if(i==j)
{
T tmp=a[left];
a[left]=a[i];
a[i]=tmp;
}
quicksort(a,left,i-1);
quicksort(a,i+1,right);
}
int main()
{
//I know there's a better way to do this. But I am not happy now. So I won't think anything.
for(int i=1;i<26;i++)
{
for(int j=1;j<26;j++)
{
for(int k=1;k<26;k++)
{
for(int x=1;x<26;x++)
{
if(i+j+k+x==26)
{
if(i*j*k*x==880)
{
data[0]=i;
data[1]=j;
data[2]=k;
data[3]=x;
quicksort(data,0,3);
int diff=data[1]-data[0];
for(int p=0;p<20;p++)
{
sprintf(buff,"%d ",data[0]);
strcat(cmdline,buff);
data[0]+=diff;
}
cmdline[strlenx(cmdline)-1]='\0';
puts(cmdline);
return 0;
}
}
}
}
}
}
}