HDU2000
# include <iostream>
using namespace std;
int main ( ) {
char a, b, c;
while ( cin>> a>> b>> c) {
if ( a> b) swap ( a, b) ;
if ( a> c) swap ( a, c) ;
if ( b> c) swap ( b, c) ;
cout<< a<< " " << b<< " " << c<< endl;
}
return 0 ;
}
HDU2001
# include <iostream>
# include <cmath>
# include <cstdio>
using namespace std;
struct Point {
double x, y;
} ;
istream& operator >> ( istream & in, Point & p) {
in>> p. x>> p. y;
return in;
}
double calc_distance ( const Point & p1, const Point & p2) {
return sqrt ( ( p1. x- p2. x) * ( p1. x- p2. x) + ( p1. y- p2. y) * ( p1. y- p2. y) ) ;
}
int main ( ) {
Point p1, p2;
while ( cin>> p1>> p2) {
printf ( "%.2f\n" , calc_distance ( p1, p2) ) ;
}
return 0 ;
}
HDU2002
# include <iostream>
# include <cmath>
# include <cstdio>
using namespace std;
# define PI 3.1415927
int main ( ) {
double r;
while ( cin>> r) {
double v= 4.0 / 3 * PI* r* r* r;
printf ( "%.3f\n" , v) ;
}
return 0 ;
}
HDU2003
# include <iostream>
# include <cstdio>
using namespace std;
int main ( ) {
double x;
while ( cin>> x) {
x= x> 0 ? x: - x;
printf ( "%.2f\n" , x) ;
}
return 0 ;
}
HDU2004
# include <iostream>
using namespace std;
int main ( ) {
int score;
while ( cin>> score) {
if ( score>= 90 && score<= 100 ) {
cout<< "A" << endl;
}
else if ( score>= 80 && score<= 89 ) {
cout<< "B" << endl;
}
else if ( score>= 70 && score<= 79 ) {
cout<< "C" << endl;
}
else if ( score>= 60 && score<= 69 ) {
cout<< "D" << endl;
}
else if ( score>= 0 && score<= 59 ) {
cout<< "E" << endl;
}
else {
cout<< "Score is error!" << endl;
}
}
return 0 ;
}
HDU2005
# include <cstdio>
using namespace std;
bool is_leap_year ( int year) {
if ( year% 400 == 0 ) return true ;
if ( year% 4 == 0 && year% 100 != 0 ) return true ;
return false ;
}
int main ( ) {
int day1[ ] = { 31 , 28 , 31 , 30 , 31 , 30 , 31 , 31 , 30 , 31 , 30 , 31 } ;
int day2[ ] = { 31 , 29 , 31 , 30 , 31 , 30 , 31 , 31 , 30 , 31 , 30 , 31 } ;
int year, month, day;
while ( scanf ( "%d/%d/%d" , & year, & month, & day) != EOF ) {
int * p_day= nullptr ;
if ( is_leap_year ( year) ) p_day= day2;
else p_day= day1;
int total_day= 0 ;
for ( int i= 0 ; i< month- 1 ; i++ )
total_day+= p_day[ i] ;
total_day+= day;
printf ( "%d\n" , total_day) ;
}
return 0 ;
}
HDU2006
# include <iostream>
using namespace std;
int main ( ) {
int n;
while ( cin>> n) {
int product= 1 ;
for ( int i= 0 ; i< n; i++ ) {
int value;
cin>> value;
if ( value% 2 == 1 ) {
product*= value;
}
}
cout<< product<< endl;
}
return 0 ;
}
HDU2007
# include <iostream>
using namespace std;
using ll= long long ;
int main ( ) {
ll m, n;
while ( cin>> m>> n) {
int square= 0 , cube= 0 ;
if ( m> n) swap ( m, n) ;
for ( ll i= m; i<= n; i++ ) {
if ( i% 2 == 1 ) {
cube+= i* i* i;
}
else {
square+= i* i;
}
}
cout<< square<< " " << cube<< endl;
}
return 0 ;
}
HDU2008
# include <iostream>
using namespace std;
int main ( ) {
int n;
while ( cin>> n) {
if ( n== 0 ) break ;
int negative= 0 , zero= 0 , positive= 0 ;
for ( int i= 0 ; i< n; i++ ) {
double value;
cin>> value;
if ( value> 0 ) positive++ ;
else if ( value< 0 ) negative++ ;
else zero++ ;
}
cout<< negative<< " " << zero<< " " << positive<< endl;
}
return 0 ;
}
HDU2009
# include <cstdio>
# include <cmath>
using namespace std;
int main ( ) {
double n;
int m;
while ( scanf ( "%lf%d" , & n, & m) != EOF ) {
double sum= 0 ;
for ( int i= 0 ; i< m; i++ ) {
sum+= n;
n= sqrt ( n) ;
}
printf ( "%.2f\n" , sum) ;
}
return 0 ;
}
HDU2010
# include <iostream>
# include <vector>
using namespace std;
bool is_narcissistic_number ( int number) {
vector< int > v;
int num= number;
while ( num) {
v. push_back ( num% 10 ) ;
num/= 10 ;
}
int sum= 0 ;
for ( int i: v) {
sum+= i* i* i;
}
return sum== number;
}
int main ( ) {
int m, n;
while ( cin>> m>> n) {
vector< int > narcissistic_number;
for ( int i= m; i<= n; i++ ) {
if ( is_narcissistic_number ( i) )
narcissistic_number. push_back ( i) ;
}
if ( narcissistic_number. empty ( ) ) {
cout<< "no" << endl;
}
else {
cout<< narcissistic_number[ 0 ] ;
for ( int i= 1 ; i< narcissistic_number. size ( ) ; i++ ) {
cout<< " " << narcissistic_number[ i] ;
}
cout<< endl;
}
}
return 0 ;
}
HDU2011
# include <iostream>
# include <cstdio>
using namespace std;
int main ( ) {
int m;
cin>> m;
for ( int i= 0 ; i< m; i++ ) {
int n;
cin>> n;
double sum= 0 ;
for ( int i= 1 ; i<= n; i++ ) {
double v= 1.0 / i;
if ( i% 2 == 0 )
v= - v;
sum+= v;
}
printf ( "%.2f\n" , sum) ;
}
return 0 ;
}
HDU2012
# include <iostream>
using namespace std;
bool is_prime ( int num) {
for ( int i= 2 ; i* i<= num; i++ ) {
if ( num% i== 0 )
return false ;
}
return true ;
}
int main ( ) {
int x, y;
while ( cin>> x>> y) {
if ( ! x&& ! y) break ;
bool f= true ;
for ( int i= x; i<= y; i++ ) {
if ( ! is_prime ( i* i+ i+ 41 ) ) {
f= false ;
break ;
}
}
if ( f) {
cout<< "OK" << endl;
}
else {
cout<< "Sorry" << endl;
}
}
return 0 ;
}
HDU2013
# include <iostream>
using namespace std;
int main ( ) {
int n;
while ( cin>> n) {
int sum= 1 ;
for ( int i= 1 ; i< n; i++ ) {
sum= ( sum+ 1 ) * 2 ;
}
cout<< sum<< endl;
}
return 0 ;
}
HDU2014
# include <iostream>
# include <vector>
# include <algorithm>
# include <numeric>
# include <cstdio>
using namespace std;
int main ( ) {
int n;
while ( cin>> n) {
vector< int > v ( n) ;
for ( int & i: v) {
cin>> i;
}
sort ( v. begin ( ) , v. end ( ) ) ;
double sum= accumulate ( v. begin ( ) + 1 , v. end ( ) - 1 , 0.0 ) ;
double score= sum/ ( v. size ( ) - 2 ) ;
printf ( "%.2f\n" , score) ;
}
return 0 ;
}
HDU2015
# include <iostream>
using namespace std;
int main ( ) {
int n, m;
while ( cin>> n>> m) {
int begin= 2 ;
while ( n> 0 ) {
int ave;
if ( n> m) {
ave= begin+ m- 1 ;
begin= begin+ 2 * m;
}
else {
ave= begin+ n- 1 ;
} ;
cout<< ave;
n-= m;
if ( n> 0 ) {
cout<< " " ;
}
}
cout<< endl;
}
return 0 ;
}
HDU2016
# include <iostream>
# include <vector>
# include <algorithm>
using namespace std;
int main ( ) {
int n;
while ( cin>> n) {
if ( ! n) break ;
vector< int > v ( n) ;
for ( int & i: v) {
cin>> i;
}
vector< int > :: iterator min_position= min_element ( v. begin ( ) , v. end ( ) ) ;
swap ( * min_position, v[ 0 ] ) ;
cout<< v[ 0 ] ;
for ( int i= 1 ; i< v. size ( ) ; i++ )
cout<< " " << v[ i] ;
cout<< endl;
}
return 0 ;
}
HDU2017
# include <iostream>
# include <string>
using namespace std;
int main ( ) {
int n;
cin>> n;
while ( n-- ) {
string s;
cin>> s;
int cnt= 0 ;
for ( char c: s) {
if ( c>= '0' && c<= '9' ) {
cnt++ ;
}
}
cout<< cnt<< endl;
}
return 0 ;
}
HDU2018
# include <iostream>
using namespace std;
long long a[ 60 ] , b[ 60 ] , c[ 60 ] , d[ 60 ] ;
void pre ( ) {
a[ 1 ] = b[ 1 ] = b[ 1 ] = 0 , d[ 1 ] = 1 ;
for ( int i= 2 ; i<= 55 ; i++ ) {
d[ i] = c[ i- 1 ] + d[ i- 1 ] ;
a[ i] = d[ i] ;
b[ i] = a[ i- 1 ] ;
c[ i] = b[ i- 1 ] ;
}
}
int main ( ) {
pre ( ) ;
int n;
while ( cin>> n) {
if ( ! n) break ;
cout<< a[ n] + b[ n] + c[ n] + d[ n] << endl;
}
return 0 ;
}
HDU2019
# include <iostream>
# include <vector>
using namespace std;
int main ( ) {
int n, m;
while ( cin>> n>> m) {
if ( ! n&& ! m) break ;
vector< int > v ( n) ;
for ( int & i: v) {
cin>> i;
}
bool insert= false ;
vector< int > v2;
for ( int & i: v) {
if ( i> m&& ! insert) {
v2. push_back ( m) ;
insert= true ;
}
v2. push_back ( i) ;
}
cout<< v2[ 0 ] ;
for ( int i= 1 ; i< v2. size ( ) ; i++ )
cout<< " " << v2[ i] ;
cout<< endl;
}
return 0 ;
}
HDU2020
# include <iostream>
# include <vector>
# include <cmath>
# include <algorithm>
using namespace std;
bool cmp ( const int & x, const int & y) {
return abs ( x) > abs ( y) ;
}
int main ( ) {
int n;
while ( cin>> n) {
if ( ! n) break ;
vector< int > v ( n) ;
for ( int & i: v) {
cin>> i;
}
sort ( v. begin ( ) , v. end ( ) , cmp) ;
cout<< v[ 0 ] ;
for ( int i= 1 ; i< v. size ( ) ; i++ )
cout<< " " << v[ i] ;
cout<< endl;
}
return 0 ;
}
HDU2021
# include <iostream>
# include <vector>
using namespace std;
vector< int > v= { 100 , 50 , 10 , 5 , 2 , 1 } ;
int main ( ) {
int n;
while ( cin>> n) {
if ( ! n) break ;
int sum= 0 ;
for ( int i= 0 ; i< n; i++ ) {
int salary;
cin>> salary;
for ( int & i: v) {
sum+= salary/ i;
salary%= i;
}
}
cout<< sum<< endl;
}
return 0 ;
}
HDU2022
# include <iostream>
# include <cmath>
using namespace std;
int main ( ) {
int n, m;
while ( cin>> n>> m) {
int abs_max= 0 ;
int row= 1 , col= 1 ;
for ( int i= 1 ; i<= n; i++ ) {
for ( int j= 1 ; j<= m; j++ ) {
int tmp;
cin>> tmp;
if ( abs ( tmp) > abs ( abs_max) ) {
abs_max= tmp;
row= i;
col= j;
}
}
}
cout<< row<< " " << col<< " " << abs_max<< endl;
}
return 0 ;
}
HDU2023
# include <iostream>
# include <vector>
# include <cstdio>
using namespace std;
struct Student {
vector< double > scores;
} ;
int main ( ) {
int n, m;
while ( cin >> n >> m) {
vector< Student> student ( n) ;
for ( int i = 0 ; i < n; i++ ) {
for ( int j = 0 ; j < m; j++ ) {
double score;
cin >> score;
student[ i] . scores. push_back ( score) ;
}
}
vector< double > student_ave;
for ( int i = 0 ; i < n; i++ ) {
double sum = 0 ;
for ( double score : student[ i] . scores) {
sum += score;
}
double ave = sum / m;
student_ave. push_back ( ave) ;
}
printf ( "%.2f" , student_ave[ 0 ] ) ;
for ( int i = 1 ; i < student_ave. size ( ) ; i++ ) {
printf ( " %.2f" , student_ave[ i] ) ;
}
cout << endl;
vector< double > class_ave;
for ( int i = 0 ; i < m; i++ ) {
double sum = 0 ;
for ( int j = 0 ; j < n; j++ ) {
sum += student[ j] . scores[ i] ;
}
double ave = sum / n;
class_ave. push_back ( ave) ;
}
printf ( "%.2f" , class_ave[ 0 ] ) ;
for ( int i = 1 ; i < class_ave. size ( ) ; i++ ) {
printf ( " %.2f" , class_ave[ i] ) ;
}
cout << endl;
int cnt = 0 ;
for ( int i = 0 ; i < n; i++ ) {
bool f = true ;
for ( int j = 0 ; j < m; j++ ) {
if ( student[ i] . scores[ j] >= class_ave[ j] ) {
}
else {
f = false ;
break ;
}
}
if ( f) {
cnt++ ;
}
}
cout << cnt << endl << endl;
}
return 0 ;
}
HDU2024
# include <iostream>
# include <cctype>
# include <string>
using namespace std;
bool check ( string s) {
if ( isalpha ( s[ 0 ] ) || s[ 0 ] == '_' ) {
for ( char c : s) {
if ( isalnum ( c) || c == '_' ) {
}
else {
return false ;
}
}
}
else {
return false ;
}
return true ;
}
int main ( ) {
int n;
while ( cin >> n) {
cin. ignore ( 1024 , '\n' ) ;
for ( int i = 0 ; i < n; i++ ) {
string s;
getline ( cin, s) ;
if ( check ( s) ) {
cout << "yes" << endl;
}
else {
cout << "no" << endl;
}
}
}
return 0 ;
}
HDU2025
# include <iostream>
# include <string>
# include <algorithm>
using namespace std;
int main ( ) {
string s;
while ( cin >> s) {
char max_c = * max_element ( s. begin ( ) , s. end ( ) ) ;
string ss = "" ;
for ( char c : s) {
if ( c == max_c) {
ss += c;
ss += "(max)" ;
}
else {
ss += c;
}
}
cout << ss << endl;
}
return 0 ;
}
HDU2026
# include <iostream>
# include <string>
# include <cctype>
using namespace std;
int main ( ) {
string s;
while ( getline ( cin, s) ) {
if ( isalpha ( s[ 0 ] ) ) {
s[ 0 ] = toupper ( s[ 0 ] ) ;
}
for ( int i = 1 ; i < s. length ( ) ; i++ ) {
if ( isalpha ( s[ i] ) && isspace ( s[ i - 1 ] ) ) {
s[ i] = toupper ( s[ i] ) ;
}
}
cout << s << endl;
}
return 0 ;
}
HDU2027
# include <iostream>
# include <string>
using namespace std;
int main ( ) {
int n;
cin >> n;
cin. ignore ( 1024 , '\n' ) ;
while ( n-- ) {
string s;
getline ( cin, s) ;
int num1 = 0 , num2 = 0 , num3 = 0 , num4 = 0 , num5 = 0 ;
for ( char c : s) {
if ( c == 'a' ) num1++ ;
else if ( c == 'e' ) num2++ ;
else if ( c == 'i' ) num3++ ;
else if ( c == 'o' ) num4++ ;
else if ( c == 'u' ) num5++ ;
}
cout << "a:" << num1 << endl;
cout << "e:" << num2 << endl;
cout << "i:" << num3 << endl;
cout << "o:" << num4 << endl;
cout << "u:" << num5 << endl;
if ( n)
cout << endl;
}
}
HDU2028
# include <iostream>
using namespace std;
using ll = long long ;
ll gcd ( ll x, ll y) {
if ( x% y == 0 )
return y;
else
return gcd ( y, x% y) ;
}
ll lcm ( ll x, ll y) {
return x * y / gcd ( x, y) ;
}
int main ( ) {
int n;
while ( cin >> n) {
ll _lcm;
cin >> _lcm;
for ( int i = 1 ; i < n; i++ ) {
ll v;
cin >> v;
_lcm = lcm ( _lcm, v) ;
}
cout << _lcm << endl;
}
return 0 ;
}
HDU2029
# include <iostream>
# include <string>
# include <algorithm>
using namespace std;
int main ( ) {
int n;
cin >> n;
while ( n-- ) {
string s;
cin >> s;
string r_s = s;
reverse ( r_s. begin ( ) , r_s. end ( ) ) ;
if ( s == r_s) {
cout << "yes" << endl;
}
else {
cout << "no" << endl;
}
}
return 0 ;
}
HDU2030
# include <iostream>
# include <string>
using namespace std;
int main ( ) {
int n;
cin >> n;
cin. ignore ( 1024 , '\n' ) ;
while ( n-- ) {
string s;
getline ( cin, s) ;
int cnt = 0 ;
for ( char c : s) {
if ( c < 0 ) {
cnt++ ;
}
}
cout << cnt/ 2 << endl;
}
return 0 ;
}
HDU2031
# include <iostream>
# include <algorithm>
# include <string>
using namespace std;
using ll = long long ;
string num = "0123456789ABCDEF" ;
int main ( ) {
ll n, r;
while ( cin >> n >> r) {
bool negative = true ;
if ( n < 0 ) {
negative = false ;
n = - n;
}
string out;
while ( n) {
out += num[ n% r] ;
n /= r;
}
if ( ! negative)
out += '-' ;
reverse ( out. begin ( ) , out. end ( ) ) ;
cout << out << endl;
}
return 0 ;
}
HDU2032
# include <iostream>
# include <vector>
using namespace std;
using ll = long long ;
vector< vector< ll>> triangle ( 35 ) ;
void pre ( ) {
triangle[ 1 ] . push_back ( 1 ) ;
for ( int i = 2 ; i <= 30 ; i++ ) {
triangle[ i] . push_back ( 1 ) ;
for ( int j = 1 ; j < i - 1 ; j++ ) {
triangle[ i] . push_back ( triangle[ i - 1 ] [ j] + triangle[ i - 1 ] [ j - 1 ] ) ;
}
triangle[ i] . push_back ( 1 ) ;
}
}
int main ( ) {
pre ( ) ;
int n;
while ( cin >> n) {
for ( int i = 1 ; i <= n; i++ ) {
cout << triangle[ i] [ 0 ] ;
for ( int j = 1 ; j < triangle[ i] . size ( ) ; j++ ) {
cout << " " << triangle[ i] [ j] ;
}
cout << endl;
}
cout << endl;
}
return 0 ;
}