团体程序设计天梯赛-L1题解
L1-001 Hello World (5分)
#include <iostream>
using namespace std;
int main ( )
{
cout<< "Hello World!" << endl;
return 0 ;
}
L1-002 打印沙漏 (20分)
#include <iostream>
using namespace std;
int main ( )
{
int n;
char ch;
cin>> n>> ch;
int row= 1 , sum= 1 , cnt= 0 ;
while ( 1 )
{
sum+ = 2 * ( 2 * ( row+ 1 ) - 1 ) ;
if ( sum> n) break ;
row++ ;
}
for ( int i= 1 ; i<= row; i++ )
{
for ( int k= 0 ; k< i- 1 ; k++ )
{
cout<< " " ;
}
for ( int j= 0 ; j< 2 * ( row- i+ 1 ) - 1 ; j++ )
{
cout<< ch;
cnt++ ;
}
cout<< endl;
}
for ( int i= row- 1 ; i>= 1 ; i-- )
{
for ( int k= 0 ; k< i- 1 ; k++ )
{
cout<< " " ;
}
for ( int j= 0 ; j< 2 * ( row- i+ 1 ) - 1 ; j++ )
{
cout<< ch;
cnt++ ;
}
cout<< endl;
}
cout<< n- cnt<< endl;
return 0 ;
}
L1-003 个位数统计 (15分)
#include <iostream>
using namespace std;
int count[ 10 ] ;
int main ( )
{
string s;
cin>> s;
for ( int i= 0 ; i< s. size ( ) ; i++ )
{
count[ s[ i] - '0' ] ++ ;
}
for ( int i= 0 ; i< 10 ; i++ ) / 0 -- 9
{
if ( count[ i] )
{
cout<< i<< ":" << count[ i] << endl;
}
}
return 0 ;
}
L1-004 计算摄氏温度 (5分)
#include <iostream>
using namespace std;
int main ( )
{
int t;
cin>> t;
cout<< "Celsius = " << 5 * ( t- 32 ) / 9 << endl;
return 0 ;
}
L1-005 考试座位号 (15分)
#include <iostream>
using namespace std;
struct node
{
int id;
string s;
int num;
} stu[ 2000 ] ;
int main ( )
{
int n;
cin>> n;
while ( n-- )
{
string s;
int id;
int num;
cin>> s>> id>> num;
stu[ id] . s= s;
stu[ id] . num= num;
}
int k;
cin>> k;
while ( k-- )
{
int x;
cin>> x;
cout<< stu[ x] . s<< " " << stu[ x] . num<< endl;
}
return 0 ;
}
L1-006 连续因子 (20分)
#include <bits/stdc++.h>
using namespace std;
int main ( )
{
int n;
cin >> n;
int Maxlen = 0 ;
int b = 0 ;
for ( int i = 2 ; i < sqrt ( n) ; i++ )
{
long long sum = 1 ;
for ( int j = i; sum * j <= n; j++ )
{
sum * = j;
if ( n % sum == 0 && ( j - i + 1 ) > Maxlen)
{
Maxlen = j - i + 1 ;
b = i;
}
}
}
if ( Maxlen == 0 )
cout << "1\n"
<< n;
else
{
cout << Maxlen << endl;
for ( int i = b; i < Maxlen + b; i++ )
{
if ( i == b)
cout << i;
else
cout << "*" << i;
}
}
return 0 ;
}
L1-007 念数字 (10分)
#include <iostream>
using namespace std;
int main ( )
{
char num[ 11 ] [ 20 ] = { "ling" , "yi" , "er" , "san" , "si" , "wu" , "liu" , "qi" , "ba" , "jiu" } ;
string s;
cin>> s;
for ( int i= 0 ; i< s. size ( ) ; i++ )
{
if ( i) cout<< " " ;
if ( s[ i] == '-' ) cout<< "fu" ;
else cout<< num[ s[ i] - '0' ] ;
}
return 0 ;
}
L1-008 求整数段和 (10分)
#include <iostream>
#include <cstdio>
using namespace std;
int sum= 0 ;
int main ( )
{
int m, n;
cin>> m>> n;
int cnt= 0 ;
for ( int i= m; i<= n; i++ )
{
printf ( "%5d" , i) ;
cnt++ ;
sum+ = i;
if ( cnt% 5 == 0 && i!= n)
printf ( "\n" ) ;
}
printf ( "\nSum = %d\n" , sum) ;
return 0 ;
}
L1-009 N个数求和 (20分)
#include <bits/stdc++.h>
using namespace std;
int main ( )
{
int n;
cin >> n;
int a, b, a1 = 0 , b1 = 1 ;
scanf ( "%d/%d" , & a, & b) ;
int x = __gcd ( a, b) ;
a = a / x;
b = b / x;
for ( int i = 1 ; i < n; i++ )
{
scanf ( "%d/%d" , & a1, & b1) ;
int minn = b * b1 / __gcd ( b, b1) ;
a = a * ( minn / b) + a1 * ( minn / b1) ;
b = minn;
int x = __gcd ( a, b) ;
a = a / x;
b = b / x;
}
if ( a == 0 )
cout << "0" ;
else if ( abs ( a) > b)
{
if ( abs ( a) % b != 0 )
cout << abs ( a) / b << " " << a % b << "/" << b;
else
cout << a / b;
}
else
cout << a << "/" << b;
return 0 ;
}
L1-011 A-B (20分)
#include <iostream>
#include <algorithm>
int vis[ 1000 ] ;
using namespace std;
int main ( )
{
string a;
string b;
getline ( cin, a) ;
getline ( cin, b) ;
for ( int i = 0 ; i < b. size ( ) ; i++ )
{
vis[ b[ i] ] = 1 ;
}
for ( int i = 0 ; i < a. size ( ) ; i++ )
{
if ( vis[ a[ i] ] == 0 )
cout << a[ i] ;
}
return 0 ;
}
L1-012 计算指数 (5分)
#include <iostream>
using namespace std;
int main ( )
{
int n;
cin >> n;
cout << "2^" << n << " = " << ( 1 << n) ;
return 0 ;
}
L1-013 计算阶乘和 (10分)
#include <iostream>
using namespace std;
int jie ( int n)
{
for ( int i = n - 1 ; i > 1 ; i-- )
n * = i;
return n;
}
int main ( )
{
int n, sum = 0 ;
cin >> n;
for ( int i = 1 ; i <= n; i++ )
{
sum + = jie ( i) ;
}
cout << sum;
return 0 ;
}
L1-014 简单题 (5分)
#include <bits/stdc++.h>
using namespace std;
int main ( )
{
cout << "This is a simple problem." ;
return 0 ;
}
L1-015 跟奥巴马一起画方块 (15分)
#include <bits/stdc++.h>
using namespace std;
int main ( )
{
int n;
string s;
cin >> n >> s;
for ( int i = 0 ; i < ( n + 1 ) / 2 ; i++ )
{
for ( int j = 0 ; j < n; j++ )
cout << s;
cout << endl;
}
return 0 ;
}
L1-016 查验身份证 (15分)
#include <iostream>
using namespace std;
char M[ ] = "10X98765432" ;
int Q[ ] = { 7 , 9 , 10 , 5 , 8 , 4 , 2 , 1 , 6 , 3 , 7 , 9 , 10 , 5 , 8 , 4 , 2 } ;
int main ( )
{
int N, F = 0 ;
cin >> N;
getchar ( ) ;
while ( N-- )
{
string s;
getline ( cin, s) ;
int sum = 0 , f = 0 ;
for ( int i = 0 ; i < 17 ; i++ )
{
sum + = Q[ i] * ( s[ i] - '0' ) ;
}
int Z = sum % 11 ;
if ( s[ 17 ] != M[ Z] )
f = F = 1 ;
if ( f)
cout << s << endl;
}
if ( ! F)
cout << "All passed" ;
return 0 ;
}
L1-017 到底有多二 (15分)
#include <bits/stdc++.h>
using namespace std;
int cnttwo;
int main ( )
{
string s;
cin >> s;
for ( int i = 0 ; i < s. size ( ) ; i++ )
{
if ( s[ i] == '2' )
cnttwo++ ;
}
double ans = cnttwo * 1.0 / ( isdigit ( s[ 0 ] ) ? s. size ( ) : s. size ( ) - 1 ) ;
if ( s[ 0 ] == '-' )
ans * = 1.5 ;
if ( ( s. back ( ) - '0' ) % 2 == 0 )
ans * = 2 ;
cout << fixed << setprecision ( 2 ) << ans * 100 << "%" ;
return 0 ;
}
L1-018 大笨钟 (10分)
#include <bits/stdc++.h>
using namespace std;
int main ( )
{
int hh, mm;
char ch;
cin >> hh >> ch >> mm;
if ( hh <= 12 )
{
printf ( "Only %02d:%02d. Too early to Dang." , hh, mm) ;
}
else
{
if ( mm == 0 )
{
for ( int i = 0 ; i < hh - 12 ; i++ )
printf ( "Dang" ) ;
}
else
{
for ( int i = 0 ; i <= hh - 12 ; i++ )
printf ( "Dang" ) ;
}
}
return 0 ;
}
L1-019 谁先倒 (15分)
#include <bits/stdc++.h>
using namespace std;
int main ( )
{
int jia, yi;
cin >> jia >> yi;
int n;
int suma = 0 , sumb = 0 ;
cin >> n;
while ( n-- )
{
int a, b, c, d;
cin >> a >> b >> c >> d;
if ( a + c == b && a + c == d)
continue ;
if ( a + c == b)
suma++ ;
if ( a + c == d)
sumb++ ;
if ( suma > jia)
{
cout << "A" << endl
<< sumb << endl;
break ;
}
if ( sumb > yi)
{
cout << "B" << endl
<< suma << endl;
break ;
}
}
}
L1-020 帅到没朋友 (20分)
#include <bits/stdc++.h>
using namespace std;
map< int , int > mp;
int main ( )
{
int n;
cin>> n;
int f= 0 ;
while ( n-- )
{
int k, x;
cin>> k;
if ( k== 1 ) { cin>> x; continue ; }
for ( int i= 0 ; i< k; i++ )
{
int x;
cin>> x;
mp[ x] = 1 ;
}
}
int m;
cin>> m;
for ( int i= 0 ; i< m; i++ )
{
int e;
cin>> e;
if ( mp[ e] == 0 )
{
if ( f) cout<< " " ;
printf ( "%05d" , e) , f= 1 , mp[ e] = 1 ;
}
}
if ( f== 0 )
cout<< "No one is handsome" << endl;
return 0 ;
}
L1-021 重要的话说三遍 (5分)
#include <bits/stdc++.h>
using namespace std;
int main ( )
{
cout<< "I'm gonna WIN!" << "\n" ;
cout<< "I'm gonna WIN!" << "\n" ;
cout<< "I'm gonna WIN!" ;
return 0 ;
}
L1-022 奇偶分家 (10分)
#include <bits/stdc++.h>
using namespace std;
int main ( )
{
int jishu= 0 , oushu= 0 ;
int n;
cin>> n;
for ( int i= 0 ; i< n; i++ )
{
int num;
cin>> num;
if ( num% 2 == 0 )
oushu++ ;
else
jishu++ ;
}
printf ( "%d %d" , jishu, oushu) ;
return 0 ;
}
L1-023 输出GPLT (20分)
#include <bits/stdc++.h>
using namespace std;
map< char , int > mp;
int main ( )
{
string s;
cin>> s;
for ( int i= 0 ; i< s. size ( ) ; i++ )
{
s[ i] = toupper ( s[ i] ) ;
mp[ s[ i] ] ++ ;
}
while ( mp[ 'G' ] || mp[ 'P' ] || mp[ 'L' ] || mp[ 'T' ] )
{
if ( mp[ 'G' ] ) { cout<< "G" ; mp[ 'G' ] -- ; }
if ( mp[ 'P' ] ) { cout<< "P" ; mp[ 'P' ] -- ; }
if ( mp[ 'L' ] ) { cout<< "L" ; mp[ 'L' ] -- ; }
if ( mp[ 'T' ] ) { cout<< "T" ; mp[ 'T' ] -- ; }
}
return 0 ;
}
L1-024 后天 (5分)
#include <bits/stdc++.h>
using namespace std;
int main ( )
{
int n;
cin>> n;
cout<< ( n+ 1 ) % 7 + 1 ;
return 0 ;
}
L1-025 正整数A+B (15分)
#include <bits/stdc++.h>
using namespace std;
int check ( string s)
{
for ( int i= 0 ; i< s. size ( ) ; i++ )
{
if ( ! isdigit ( s[ i] ) )
return - 1 ;
}
if ( stoi ( s) >= 1 && stoi ( s) <= 1000 )
return stoi ( s) ;
return - 1 ;
}
int main ( )
{
string a, b;
cin>> a;
getchar ( ) ;
getline ( cin, b) ;
int n, m;
n= check ( a) ;
m= check ( b) ;
if ( n== - 1 )
printf ( "? + " ) ;
else
printf ( "%d + " , n) ;
if ( m== - 1 )
printf ( "? = " ) ;
else
printf ( "%d = " , m) ;
if ( n== - 1 || m== - 1 )
printf ( "?\n" ) ;
else
printf ( "%d\n" , n+ m) ;
return 0 ;
}
L1-026 I Love GPLT (5分)
#include <stdio.h>
int main ( )
{
printf ( "I\n \nL\no\nv\ne\n \nG\nP\nL\nT\n" ) ;
return 0 ;
}
L1-027 出租 (20分)
#include <bits/stdc++.h>
using namespace std;
int main ( )
{
set< char , greater< >> st;
string s;
int a[ 20 ] ;
cin>> s;
for ( int i= 0 ; i< s. size ( ) ; i++ )
{
st. insert ( s[ i] ) ;
}
cout<< "int[] arr = new int[]{" ;
int f= 0 ;
for ( auto e: st)
{
if ( f) cout<< "," ;
cout<< e;
a[ e- '0' ] = f++ ;
}
cout<< "};" << endl;
cout<< "int[] index = new int[]{" ;
f= 0 ;
for ( int i= 0 ; i< s. size ( ) ; i++ )
{
if ( f) cout<< "," ;
cout<< a[ s[ i] - '0' ] , f= 1 ;
}
cout<< "};" ;
return 0 ;
}
L1-028 判断素数 (10分)
#include <bits/stdc++.h>
using namespace std;
int f ( int n)
{
if ( n== 1 ) return 0 ;
for ( int i = 2 ; i <= sqrt ( n) ; i++ )
{
if ( n % i == 0 )
return 0 ;
}
return 1 ;
}
int main ( )
{
int n;
cin >> n;
for ( int i = 0 ; i < n; i++ )
{
int num;
cin >> num;
if ( f ( num) == 0 )
cout << "No" << endl;
else
cout << "Yes" << endl;
}
return 0 ;
}
L1-029 是不是太胖了 (5分)
#include <bits/stdc++.h>
using namespace std;
int main ( )
{
int n;
cin>> n;
cout<< fixed<< setprecision ( 1 ) << ( n- 100 ) * 0.9 * 2 ;
return 0 ;
}
L1-030 一帮一 (15分)
#include <iostream>
#include <map>
using namespace std;
map< string, int > mp;
struct node
{
int sex;
string name;
} stu[ 100 ] ;
int main ( )
{
int n;
cin >> n;
for ( int i = 0 ; i < n; i++ )
{
cin >> stu[ i] . sex >> stu[ i] . name;
}
for ( int i = 0 ; i < n; i++ )
{
if ( stu[ i] . sex == 0 && mp[ stu[ i] . name] == 0 )
{
for ( int j = n - 1 ; j > i; j-- )
{
if ( stu[ j] . sex == 1 && mp[ stu[ j] . name] == 0 )
{
cout << stu[ i] . name << " " << stu[ j] . name << endl;
mp[ stu[ i] . name] = mp[ stu[ j] . name] = 1 ;
break ;
}
}
}
if ( stu[ i] . sex == 1 && mp[ stu[ i] . name] == 0 )
{
for ( int j = n - 1 ; j > i; j-- )
{
if ( stu[ j] . sex == 0 && mp[ stu[ j] . name] == 0 )
{
cout << stu[ i] . name << " " << stu[ j] . name << endl;
mp[ stu[ i] . name] = mp[ stu[ j] . name] = 1 ;
break ;
}
}
}
}
return 0 ;
}
L1-031 到底是不是太胖了 (10分)
#include <bits/stdc++.h>
using namespace std;
int main ( )
{
int n;
cin>> n;
while ( n-- )
{
double h, w;
cin>> h>> w;
if ( abs ( w- ( h- 100 ) * 0.9 * 2 ) < ( h- 100 ) * 0.9 * 2 * 0.1 )
cout<< "You are wan mei!" << endl;
else if ( w> ( h- 100 ) * 0.9 * 2 )
cout<< "You are tai pang le!" << endl;
else
cout<< "You are tai shou le!" << endl;
}
return 0 ;
}
L1-032 Left-pad (20分)
#include <bits/stdc++.h>
using namespace std;
int main ( )
{
int n;
char c;
cin>> n>> c;
string s, a;
getchar ( ) ;
getline ( cin, s) ;
if ( n> s. size ( ) )
{
for ( int i= 0 ; i< n- s. size ( ) ; i++ )
cout<< c;
cout<< s;
}
else
{
for ( int j= s. size ( ) - n; j< s. size ( ) ; j++ )
cout<< s[ j] ;
}
return 0 ;
}
L1-033 出生年 (15分)
#include <iostream>
#include <cstdio>
#include <set>
#include <algorithm>
using namespace std;
set< int > st;
int y, n;
int check ( int x)
{
st. clear ( ) ;
if ( x< 1000 ) st. insert ( 0 ) ;
while ( x)
{
st. insert ( x% 10 ) ;
x/ = 10 ;
}
if ( st. size ( ) == n)
return 1 ;
return 0 ;
}
int main ( )
{
cin>> y>> n;
int i;
for ( i= y; i<= 9999 ; i++ )
{
if ( check ( i) )
break ;
}
printf ( "%d %04d" , i- y, i) ;
return 0 ;
}
L1-034 点赞 (20分)
#include <bits/stdc++.h>
using namespace std; map
< int , int , greater< int >> mp;
vector< pair< int , int >> v;
bool cmp ( pair< int , int > a, pair< int , int > b)
{
return a. second== b. second? a. first> b. first: a. second> b. second;
}
int main ( )
{
int N;
int maxx= - 1 ;
cin>> N;
for ( int i= 0 ; i< N; i++ )
{
int k;
cin>> k;
while ( k-- )
{
int s;
cin>> s;
mp[ s] ++ ;
}
}
for ( auto e: mp)
{
v. push_back ( e) ;
}
sort ( v. begin ( ) , v. end ( ) , cmp) ;
cout<< v[ 0 ] . first<< " " << v[ 0 ] . second;
return 0 ;
}
L1-035 情人节 (15分)
#include <iostream>
#include <iomanip>
#include <set>
#include <algorithm>
using namespace std;
int main ( )
{
int n= 0 ;
string s, name1= "" , name2= "" ;
while ( cin>> s)
{
if ( s== "." )
break ;
n++ ;
if ( n== 2 )
name1= s;
if ( n== 14 )
name2= s;
}
if ( name1== "" )
cout<< "Momo... No one is for you ..." << endl;
else if ( name2== "" )
cout<< name1<< " is the only one for you..." << endl;
else
cout<< name1<< " and " << name2<< " are inviting you to dinner..." << endl;
return 0 ;
}
L1-036 A乘以B (5分)
#include <stdio.h>
int main ( )
{
int a, b;
scanf ( "%d%d" , & a, & b) ;
printf ( "%d" , a* b) ;
return 0 ;
}
L1-037 A除以B (10分)
#include <stdio.h>
int main ( )
{
double a, b;
scanf ( "%lf%lf" , & a, & b) ;
if ( b== 0 )
printf ( "%.0lf/%.0lf=Error" , a, b) ;
else
{
double sum= a/ b;
if ( b< 0 )
printf ( "%.0lf/(%.0lf)=%.2lf" , a, b, sum) ;
else
printf ( "%.0lf/%.0lf=%.2lf" , a, b, sum) ;
}
return 0 ;
}
L1-038 新世界 (5分)
#include <cstdio>
int main ( )
{
printf ( "Hello World\nHello New World" ) ;
return 0 ;
}
L1-039 古风排版 (20分)
#include <bits/stdc++.h>
using namespace std;
int main ( )
{
int n;
cin>> n; getchar ( ) ;
string s;
getline ( cin, s) ;
char ans[ 55 ] [ 1001 ] ;
memset ( ans, ' ' , sizeof ans) ;
int r= ( int ) ceil ( s. size ( ) * 1.0 / n) ;
int k= 0 ;
for ( int i= 0 ; i< r; i++ )
{
for ( int j= 0 ; j< n; j++ )
{
if ( k< s. size ( ) )
ans[ i] [ j] = s[ k++ ] ;
}
}
for ( int i= 0 ; i< n; i++ )
{
for ( int j= r- 1 ; j>= 0 ; j-- )
{
cout<< ans[ j] [ i] ;
}
cout<< endl;
}
return 0 ;
}
L1-040 最佳情侣身高差 (10分)
#include <iostream>
#include <iomanip>
using namespace std;
int main ( )
{
int n;
cin>> n;
while ( n-- )
{
string s;
double h;
cin>> s>> h;
if ( s== "M" )
cout<< fixed<< setprecision ( 2 ) << h* 1.0 / 1.09 << endl;
if ( s== "F" )
cout<< fixed<< setprecision ( 2 ) << h* 1.09 << endl;
}
return 0 ;
}
L1-041 寻找250 (10分)
#include <iostream>
using namespace std;
int main ( )
{
int num, cnt= 1 ;
while ( cin>> num)
{
if ( num== 250 )
{
cout<< cnt;
break ;
}
cnt++ ;
}
return 0 ;
}
L1-042 日期格式化 (5分)
#include <iostream>
using namespace std;
int main ( )
{
int a, b, c;
scanf ( "%d-%d-%d" , & a, & b, & c) ;
printf ( "%04d-%02d-%02d\n" , c, a, b) ;
return 0 ;
}
L1-043 阅览室 (20分)
#include <bits/stdc++.h>
using namespace std;
int main ( )
{
int N;
cin>> N;
while ( N-- )
{
int no, hh, mm;
int cnt= 0 , borrow[ 10000 ] = { 0 } ;
int start[ 10000 ] , sum= 0 ;
char ch;
while ( scanf ( "%d %c %d:%d" , & no, & ch, & hh, & mm) )
{
if ( no== 0 )
{
if ( ! cnt) cout<< "0 0\n" ;
else cout<< cnt<< " " << ( round) ( sum* 1.0 / cnt) << endl;
break ;
}
else if ( ch== 'S' )
{
borrow[ no] = 1 ;
start[ no] = hh* 60 + mm;
}
else if ( ch== 'E' && borrow[ no] )
{
borrow[ no] = 0 ;
sum+ = hh* 60 + mm- start[ no] ;
cnt++ ;
}
}
}
return 0 ;
}
L1-044 稳赢 (15分)
#include <iostream>
using namespace std;
int main ( )
{
int K;
cin >> K;
int i = 1 ;
string s;
while ( cin >> s, s != "End" )
{
if ( i % ( K + 1 ) == 0 )
cout << s << endl;
else if ( s == "ChuiZi" )
cout << "Bu" << endl;
else if ( s == "Bu" )
cout << "JianDao" << endl;
else if ( s == "JianDao" )
cout << "ChuiZi" << endl;
i++ ;
}
return 0 ;
}
L1-045 宇宙无敌大招呼 (5分)
#include <bits/stdc++.h>
using namespace std;
int main ( )
{
string s;
cin>> s;
cout<< "Hello " << s;
return 0 ;
}
L1-046 整除光棍 (20分)
#include <bits/stdc++.h>
using namespace std;
int main ( )
{
int x;
cin>> x;
int n= 1 , ans= 1 ;
while ( n< x)
{
n= n* 10 + 1 ;
ans++ ;
}
while ( 1 )
{
cout<< n/ x;
if ( n% x== 0 ) break ;
n= ( n% x) * 10 + 1 ;
ans++ ;
}
cout<< " " << ans;
return 0 ;
}
L1-047 装睡 (10分)
#include <iostream>
using namespace std;
int main ( )
{
int N;
cin>> N;
while ( N-- )
{
string s;
int x, y;
cin>> s>> x>> y;
if ( x< 15 || x> 20 || y< 50 || y> 70 )
cout<< s<< endl;
}
return 0 ;
}
L1-048 矩阵A乘以B (15分)
#include <iostream>
using namespace std;
int main ( )
{
int Ra, Ca, Rb, Cb;
int A[ 101 ] [ 101 ] , B[ 101 ] [ 101 ] ;
cin>> Ra>> Ca;
for ( int i= 0 ; i< Ra; i++ )
{
for ( int j= 0 ; j< Ca; j++ )
{
cin>> A[ i] [ j] ;
}
}
cin>> Rb>> Cb;
for ( int i= 0 ; i< Rb; i++ )
{
for ( int j= 0 ; j< Cb; j++ )
{
cin>> B[ i] [ j] ;
}
}
if ( Ca!= Rb)
{
cout<< "Error: " << Ca<< " != " << Rb<< endl;
}
else
{
cout<< Ra<< ' ' << Cb<< endl;
int ans[ 200 ] [ 200 ] ;
for ( int i= 0 ; i< Ra; i++ )
{
for ( int j= 0 ; j< Cb; j++ )
{
for ( int k= 0 ; k< Rb; k++ )
{
ans[ i] [ j] + = A[ i] [ k] * B[ k] [ j] ;
}
}
}
for ( int i= 0 ; i< Ra; i++ )
{
cout<< ans[ i] [ 0 ] ;
for ( int j= 1 ; j< Cb; j++ )
{
cout<< " " << ans[ i] [ j] ;
}
cout<< endl;
}
}
return 0 ;
}
L1-049 天梯赛座位分配 (20分)
#include <bits/stdc++.h>
using namespace std;
vector< int > v[ 110 ] ;
int main ( )
{
int n, num[ 101 ] ;
cin>> n;
for ( int i= 1 ; i<= n; i++ )
{
cin>> num[ i] ;
num[ i] * = 10 ;
}
int no= 1 ;
int f;
while ( 1 )
{
f= 0 ;
for ( int i= 1 ; i<= n; i++ )
{
if ( v[ i] . size ( ) < num[ i] )
{
f= 1 ;
if ( v[ i] . size ( ) == 0 ) v[ i] . push_back ( no) , no++ ;
else if ( v[ i] . back ( ) == no- 1 ) v[ i] . push_back ( no+ 1 ) , no+ = 2 ;
else v[ i] . push_back ( no) , no++ ;
}
}
if ( ! f) break ;
}
for ( int i= 1 ; i<= n; i++ )
{
cout<< "#" << i<< endl;
int j= 0 , f= 0 ;
for ( auto e: v[ i] )
{
if ( f) cout<< " " ;
cout<< e, f= 1 , j++ ;
if ( j== 10 ) cout<< endl, j= f= 0 ;
}
}
return 0 ;
}
L1-050 倒数第N个字符串 (15分)
#include <bits/stdc++.h>
using namespace std;
int main ( )
{
int L, N;
int i= 0 ;
string ch;
cin>> L>> N;
int s= pow ( 26 , L) ;
s= s- N;
while ( L-- )
{
ch+ = 'a' + s% 26 ;
s/ = 26 ;
}
reverse ( ch. begin ( ) , ch. end ( ) ) ;
cout<< ch;
return 0 ;
}
L1-051 打折 (5分)
#include <bits/stdc++.h>
using namespace std;
int main ( )
{
double n, m;
cin>> n>> m;
cout<< fixed<< setprecision ( 2 ) << n* m/ 10 ;
}
L1-052 2018我们要赢 (5分)
#include <iostream>
using namespace std;
int main ( )
{
cout<< "2018\nwo3 men2 yao4 ying2 !" ;
return 0 ;
}
L1-053 电子汪 (10分)
#include <bits/stdc++.h>
using namespace std;
int main ( )
{
int n, m;
cin>> m>> n;
while ( n+ m-- ) cout<< "Wang!" ;
return 0 ;
}
L1-054 福到了 (15分)
#include <bits/stdc++.h>
using namespace std;
int main ( )
{
char c, s[ 101 ] [ 101 ] ;
int n, flag= 0 ;
cin>> c>> n;
getchar ( ) ;
for ( int i= 0 ; i< n; i++ )
{
for ( int j= 0 ; j< n; j++ )
{
scanf ( "%c" , & s[ i] [ j] ) ;
}
getchar ( ) ;
}
for ( int i= 0 ; i< n; i++ )
{
for ( int j= 0 ; j< n; j++ )
{
if ( s[ i] [ j] != s[ n- i- 1 ] [ n- j- 1 ] )
{
flag= 1 ; break ;
}
}
}
if ( ! flag)
{
printf ( "bu yong dao le\n" ) ;
for ( int i= 0 ; i< n; i++ )
{
for ( int j= 0 ; j< n; j++ )
{
if ( s[ i] [ j] == ' ' )
printf ( " " ) ;
else
printf ( "%c" , c) ;
}
printf ( "\n" ) ;
}
}
else
{
for ( int i= 0 ; i< n; i++ )
{
for ( int j= 0 ; j< n; j++ )
{
if ( s[ n- i- 1 ] [ n- j- 1 ] == ' ' )
printf ( " " ) ;
else
printf ( "%c" , c) ;
}
printf ( "\n" ) ;
}
}
return 0 ;
}
L1-055 谁是赢家 (10分)
#include <bits/stdc++.h>
using namespace std;
int main ( )
{
int a[ 4 ] , numa= 0 , numb= 0 ;
int n, m;
cin>> n>> m;
for ( int i= 0 ; i< 3 ; i++ )
{
cin>> a[ i] ;
if ( a[ i] == 0 )
numa++ ;
else
numb++ ;
}
if ( ( n< m&& numa== 3 ) || ( n> m&& numa> 0 ) )
cout<< "The winner is a: " << n<< " " << "+" << " " << numa;
if ( ( n> m&& numb== 3 ) || ( n< m&& numb> 0 ) )
cout<< "The winner is b: " << m<< " " << "+" << " " << numb;
return 0 ;
}
L1-056 猜数字 (20分)
#include <bits/stdc++.h>
using namespace std;
map< string , int > mp;
int main ( )
{
int n;
cin>> n;
double sum= 0 ;
for ( int i= 0 ; i< n; i++ )
{
string s;
int num;
cin>> s>> num;
mp[ s] = num;
sum+ = num;
}
sum/ = n;
string ans;
double minn= 1 << 30 ;
for ( auto e: mp)
{
if ( minn> abs ( e. second- sum/ 2 ) ) ans= e. first, minn= abs ( e. second- sum/ 2 ) ;
}
cout<< ( int ) sum/ 2 << " " << ans;
return 0 ;
}
L1-057 PTA使我精神焕发 (5分)
#include <iostream>
int main ( )
{
printf ( "PTA shi3 wo3 jing1 shen2 huan4 fa1 !" ) ;
return 0 ;
}
L1-058 6翻了 (15分)
#include <bits/stdc++.h>
using namespace std;
int main ( )
{
string s;
getline ( cin, s) ;
for ( int i= 0 ; i< s. size ( ) ; i++ )
{
if ( s[ i] == '6' )
{
int j= 0 ;
for ( j= 0 ; s[ i] == '6' ; i++ , j++ ) ;
if ( j> 9 ) cout<< "27" ;
else if ( j> 3 ) cout<< "9" ;
else
while ( j-- ) cout<< "6" ;
i-- ;
}
else cout<< s[ i] ;
}
return 0 ;
}
L1-059 敲笨钟 (20分)
#include <bits/stdc++.h>
using namespace std;
int main ( )
{
int n;
cin>> n;
getchar ( ) ;
for ( int i= 0 ; i< n; i++ )
{
string s;
getline ( cin, s) ;
if ( s. find ( "ong," ) != s. npos&& s. find ( "ong." ) != s. npos)
{
int kong= 0 ;
for ( int j= s. size ( ) - 1 ; j>= 0 ; j-- )
{
if ( s[ j] == ' ' ) kong ++ ;
if ( kong == 3 ) { s. erase ( s. begin ( ) + j, s. end ( ) ) ; break ; }
}
cout<< s;
cout<< " qiao ben zhong." << endl;
}
else cout<< "Skipped" << endl;
}
return 0 ;
}
L1-060 心理阴影面积 (5分)
#include <iostream>
using namespace std;
int main ( )
{
int s1= ( 100 * 100 ) / 2 ;
int x, y;
cin>> x>> y;
int s2= ( x* y) / 2 ;
int s3= ( 100 - x) * y;
int s4= ( 100 - x) * ( 100 - y) / 2 ;
cout<< s1- s2- s3- s4;
return 0 ;
}
L1-061 新胖子公式 (10分)
#include <iostream>
#include <iomanip>
using namespace std;
int main ( )
{
double h, w;
cin>> w>> h;
double x= w/ ( h* h) ;
cout<< fixed<< setprecision ( 1 ) << x<< endl;
if ( x> 25 )
cout<< "PANG" << endl;
else
cout<< "Hai Xing" << endl;
return 0 ;
}
L1-062 幸运彩票 (15分)
#include <iostream>
using namespace std;
int main ( )
{
int N;
cin >> N;
getchar ( ) ;
while ( N-- )
{
string s;
getline ( cin, s) ;
if ( s[ 0 ] + s[ 1 ] + s[ 2 ] == s[ 3 ] + s[ 4 ] + s[ 5 ] )
cout << "You are lucky!" << endl;
else
cout << "Wish you good luck." << endl;
}
return 0 ;
}
L1-063 吃鱼还是吃肉 (10分)
#include <iostream>
using namespace std;
int main ( )
{
int N;
cin>> N;
while ( N-- )
{
int s, h, w;
cin>> s>> h>> w;
if ( s== 1 )
{
if ( h< 130 ) cout<< "duo chi yu! " ;
else if ( h== 130 ) cout<< "wan mei! " ;
else if ( h> 130 ) cout<< "ni li hai! " ;
if ( w< 27 ) cout<< "duo chi rou!" << endl;
else if ( w== 27 ) cout<< "wan mei!" << endl;
else if ( w> 27 ) cout<< "shao chi rou!" << endl;
}
else
{
if ( h< 129 ) cout<< "duo chi yu! " ;
else if ( h== 129 ) cout<< "wan mei! " ;
else if ( h> 129 ) cout<< "ni li hai! " ;
if ( w< 25 ) cout<< "duo chi rou!" << endl;
else if ( w== 25 ) cout<< "wan mei!" << endl;
else if ( w> 25 ) cout<< "shao chi rou!" << endl;
}
}
return 0 ;
}
L1-064 估值一亿的AI核心代码 (20分)
#include <iostream>
using namespace std;
bool check ( string s, int pos , int len)
{
return ! isalnum ( s[ pos- 1 ] ) && ! isalnum ( s[ pos+ len] ) ;
}
int main ( )
{
int n;
cin>> n;
getchar ( ) ;
for ( int i= 0 ; i< n ; i++ )
{
string s;
getline ( cin, s) ;
cout<< s<< endl;
for ( int i= 0 ; i< s. size ( ) ; i++ )
{
if ( isupper ( s[ i] ) && s[ i] != 'I' ) s[ i] + = 32 ;
if ( s[ i] == '?' ) s[ i] = '!' ;
}
while ( s[ 0 ] == ' ' ) s. erase ( s. begin ( ) ) ;
while ( s. back ( ) == ' ' ) s. pop_back ( ) ;
for ( int i= 0 ; i< s. size ( ) ; i++ )
{
if ( s[ i] == ' ' )
{
int j;
for ( j= i; s[ j] == ' ' ; j++ ) ;
s. replace ( i, j- i, " " ) ;
}
}
for ( int i= 0 ; i< s. size ( ) ; i++ )
{
if ( s[ i] == ' ' && ! isalnum ( s[ i+ 1 ] ) ) s. erase ( s. begin ( ) + i) ;
}
for ( int i= 0 ; i< s. size ( ) ; i++ )
{
if ( ( s. substr ( i, 1 ) == "I" ) && check ( s, i, 1 ) ) s. replace ( i, 1 , "you" ) ;
if ( ( s. substr ( i, 2 ) == "me" ) && check ( s, i, 2 ) ) s. replace ( i, 2 , "you" ) ;
if ( ( s. substr ( i, 7 ) == "can you" ) && check ( s, i, 7 ) ) s. replace ( i, 7 , "I can" ) ;
if ( ( s. substr ( i, 9 ) == "could you" ) && check ( s, i, 9 ) ) s. replace ( i, 9 , "I could" ) ;
}
cout<< "AI: " << s<< endl;
}
return 0 ;
}
L1-065 嫑废话上代码 (5分)
#include <iostream>
using namespace std;
int main ( )
{
cout<< "Talk is cheap. Show me the code." ;
return 0 ;
}
L1-066 猫是液体 (5分)
#include <iostream>
using namespace std;
int main ( )
{
int a, b, c;
cin>> a>> b>> c;
cout<< a* b* c;
return 0 ;
}
L1-067 洛希极限 (10分)
#include <bits/stdc++.h>
using namespace std;
int main ( )
{
double a, b;
int f;
cin>> a>> f>> b;
double s;
if ( f) s= a* 1.26 ;
else s= a* 2.455 ;
cout<< fixed<< setprecision ( 2 ) << s<< ( s> b ? " T_T" : " ^_^" ) ;
return 0 ;
}
L1-068 调和平均 (10分)
#include <bits/stdc++.h>
using namespace std;
int main ( )
{
int n;
cin>> n;
double sum= 0 ;
for ( int i= 0 ; i< n; i++ )
{
double num;
cin>> num;
sum+ = 1.0 / num;
}
sum/ = n;
cout<< fixed<< setprecision ( 2 ) << 1.0 / sum;
return 0 ;
}
L1-069 胎压监测 (15分)
#include <bits/stdc++.h>
using namespace std;
vector< int > v;
int main ( )
{
int a[ 10 ] , mn, f, mx= - 1 ;
for ( int i= 1 ; i<= 4 ; i++ )
{
cin>> a[ i] ;
mx= max ( mx, a[ i] ) ;
}
cin>> mn>> f;
for ( int i= 1 ; i<= 4 ; i++ )
{
if ( a[ i] < mn|| mx- a[ i] > f)
v. push_back ( i) ;
}
if ( ! v. size ( ) ) cout<< "Normal" << endl;
else if ( v. size ( ) == 1 ) cout<< "Warning: please check #" << v[ 0 ] << "!" ;
else cout<< "Warning: please check all the tires!" ;
return 0 ;
}
L1-070 吃火锅 (15分)
#include <bits/stdc++.h>
using namespace std;
vector< int > v;
int main ( )
{
int cnt= 0 , first= 0 , i= 1 ;
string s;
while ( getline ( cin, s) , s!= "." )
{
if ( s. find ( "chi1 huo3 guo1" ) != s. npos)
{
if ( ! first) first= i;
cnt++ ;
}
i++ ;
}
cout<< i- 1 << endl;
if ( ! first) cout<< "-_-#" ;
else cout<< first<< " " << cnt;
return 0 ;
}
L1-071 前世档案 (20分)
#include <bits/stdc++.h>
using namespace std;
int main ( )
{
int n, m;
cin>> n>> m;
getchar ( ) ;
while ( m-- )
{
string s;
getline ( cin, s) ;
int sum= 1 ;
for ( int i= 0 ; i< s. size ( ) ; i++ )
{
if ( s[ i] == 'y' ) sum* = 2 ;
else sum= sum* 2 + 1 ;
}
cout<< sum- ( 1 << n) + 1 << endl;
}
return 0 ;
}
L1-072 刮刮彩票 (20分)
#include <bits/stdc++.h>
using namespace std;
int mp[ 30 ] = { 0 , 0 , 0 , 0 , 0 , 0 , 10000 , 36 , 720 , 360 , 80 , 252 , 108 , 72 , 54 , 180 , 72 , 180 , 119 , 36 , 306 , 1080 , 144 , 1800 , 3600 } ;
int vis[ 100 ] ;
int main ( )
{
int a[ 110 ] [ 100 ] ;
int x, y;
for ( int i = 0 ; i < 3 ; i++ )
{
for ( int j = 0 ; j < 3 ; j++ )
{
int num;
cin >> num;
if ( num != 0 )
{
a[ i] [ j] = num;
vis[ num] = 1 ;
}
else
{
x = i, y = j;
}
}
}
for ( int k = 1 ; k <= 9 ; k++ )
{
if ( ! vis[ k] )
{
a[ x] [ y] = k;
break ;
}
}
for ( int i= 0 ; i< 3 ; i++ )
{
int b, c;
cin >> b >> c;
cout << a[ b - 1 ] [ c - 1 ] << endl;
}
int t;
cin >> t;
int sum = 0 ;
if ( t == 1 )
{
for ( int i = 0 ; i < 3 ; i++ )
sum + = a[ 0 ] [ i] ;
}
else if ( t == 2 )
{
for ( int i = 0 ; i < 3 ; i++ )
sum + = a[ 1 ] [ i] ;
}
else if ( t == 3 )
{
for ( int i = 0 ; i < 3 ; i++ )
sum + = a[ 2 ] [ i] ;
}
else if ( t == 4 )
{
for ( int i = 0 ; i < 3 ; i++ )
sum + = a[ i] [ 0 ] ;
}
else if ( t == 5 )
{
for ( int i = 0 ; i < 3 ; i++ )
sum + = a[ i] [ 1 ] ;
}
else if ( t == 6 )
{
for ( int i = 0 ; i < 3 ; i++ )
sum + = a[ i] [ 2 ] ;
}
else if ( t == 7 )
{
for ( int i = 0 ; i < 3 ; i++ )
sum + = a[ i] [ i] ;
}
else if ( t == 8 )
{
sum = a[ 0 ] [ 2 ] + a[ 1 ] [ 1 ] + a[ 2 ] [ 0 ] ;
}
cout << mp[ sum] << endl;
return 0 ;
}