1081 检查密码 (15分)
#include <bits/stdc++.h>
using namespace std;
int main ( )
{
int n;
cin>> n;
getchar ( ) ;
while ( n-- )
{
string s;
getline ( cin, s) ;
if ( s. size ( ) >= 6 )
{
int no= 0 , hasnum= 0 , haseng= 0 ;
for ( int i= 0 ; i< s. size ( ) ; i++ )
{
if ( ! isalnum ( s[ i] ) && s[ i] != '.' ) no= 1 ;
if ( isalnum ( s[ i] ) )
{
if ( isalpha ( s[ i] ) )
{
haseng= 1 ;
}
else
hasnum= 1 ;
}
}
if ( no== 1 ) cout<< "Your password is tai luan le." << endl;
else if ( ! hasnum) cout<< "Your password needs shu zi." << endl;
else if ( ! haseng) cout<< "Your password needs zi mu." << endl;
else cout<< "Your password is wan mei." << endl;
}
else
cout<< "Your password is tai duan le." << endl;
}
return 0 ;
}
1082 射击比赛 (20分)
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
struct node
{
string id;
int x, y;
int d;
} stu[ 10101 ] ;
bool cmp ( node a, node b)
{
return a. d< b. d;
}
int main ( )
{
int n;
cin>> n;
for ( int i= 0 ; i< n; i++ )
{
cin>> stu[ i] . id>> stu[ i] . x>> stu[ i] . y;
stu[ i] . d= sqrt ( stu[ i] . x* stu[ i] . x+ stu[ i] . y* stu[ i] . y) ;
}
sort ( stu, stu+ n, cmp) ;
cout<< stu[ 0 ] . id<< " " << stu[ n- 1 ] . id<< endl;
return 0 ;
}
1083 是否存在相等的差 (20分)
#include <iostream>
#include <map>
#include <cmath>
using namespace std;
map< int , int , greater< int >> mp;
int main ( )
{
int n;
cin>> n;
for ( int i= 1 ; i<= n; i++ )
{
int x;
cin>> x;
mp[ abs ( x- i) ] ++ ;
}
for ( auto e: mp)
{
if ( e. second> 1 )
cout<< e. first<< " " << e. second<< endl;
}
return 0 ;
}
1084 外观数列 (20分)
#include <bits/stdc++.h>
using namespace std;
vector< int > v1, v2;
int main ( )
{
int d, N;
cin>> d>> N;
v1. push_back ( d) ;
while ( -- N)
{
v2. clear ( ) ;
int j= 0 , cnt= 1 ;
for ( j= 0 ; j< v1. size ( ) - 1 ; j++ )
{
if ( v1[ j] == v1[ j+ 1 ] )
{
cnt++ ;
}
else
{
v2. push_back ( v1[ j] ) ;
v2. push_back ( cnt) ;
cnt= 1 ;
}
}
v2. push_back ( v1[ j] ) ;
v2. push_back ( cnt) ;
v1= v2;
}
for ( auto e: v1) cout<< e;
return 0 ;
}
1085 PAT单位排行 (25分)
#include <bits/stdc++.h>
using namespace std;
struct node
{
string name;
double score;
int num;
} ;
bool rule ( struct node a, struct node b)
{
if ( a. score!= b. score)
return a. score> b. score;
else
{
if ( a. num!= b. num)
return a. num< b. num;
else
return a. name< b. name;
}
}
map< string, struct node> mp;
int main ( )
{
int n;
cin>> n;
int k= n;
string id, school;
int score;
while ( k-- )
{
cin>> id>> score>> school;
for ( int i= 0 ; i< school. size ( ) ; i++ )
{
if ( school[ i] >= 'A' && school[ i] <= 'Z' )
school[ i] + = 32 ;
}
if ( id[ 0 ] == 'A' ) mp[ school] . score+ = score* 1.0 ;
else if ( id[ 0 ] == 'B' ) mp[ school] . score+ = score* 1.0 / 1.5 ;
else if ( id[ 0 ] == 'T' ) mp[ school] . score+ = score* 1.5 ;
mp[ school] . num++ ;
mp[ school] . name= school;
}
vector< struct node> v;
for ( auto e: mp)
{
e. second. score= ( int ) e. second. score;
v. push_back ( e. second) ;
}
sort ( v. begin ( ) , v. end ( ) , rule) ;
int s[ 100000 ] ;
for ( int i= 0 ; i< n; i++ )
{
s[ i] = i+ 1 ;
}
cout<< v. size ( ) << endl;
for ( int i= 0 ; i< v. size ( ) ; i++ )
{
if ( v[ i] . score== v[ i+ 1 ] . score)
s[ i+ 1 ] = s[ i] ;
cout<< s[ i] << " " << v[ i] . name<< " " << v[ i] . score<< " " << v[ i] . num<< endl;
}
return 0 ;
}