团体程序设计天梯赛-练习集 L1区代码
题目链接:
https://www.patest.cn/contests/gplt
1 #include<iostream> 2 using namespace std ; 3 4 int main() 5 { 6 cout << "Hello World!"<<endl; 7 return 0 ; 8 }
1 #include<iostream> 2 #include<cstdio> 3 #include<cstdlib> 4 #include<algorithm> 5 #include<cmath> 6 #include<map> 7 #include<vector> 8 #include<set> 9 using namespace std ; 10 11 int main() 12 { 13 int n ; 14 char a ; 15 cin >> n >> a ; 16 int temp = 1 , cnt = 3 ; 17 while( temp + cnt + cnt <= n ) 18 { 19 temp+=cnt+cnt; 20 cnt+=2; 21 } 22 23 cnt -= 2 ; 24 int cntt = cnt ; 25 //´òÓ¡cnt¸ö* , 26 while( cnt != 1 ) 27 { 28 for( int j = 1 ; j <= (cntt - cnt ) / 2 ; j++) 29 cout <<' ' ; 30 for( int i = 1 ; i <= cnt ; i++) 31 cout << a ; 32 cout << endl ; 33 cnt-=2; 34 35 } 36 int cnttt = cntt ; 37 for( int i = 1 ; i <= (cnttt - 1 ) / 2 ; i++) 38 cout <<" "; 39 cout << a << endl ; 40 for( int i = 3 ; i <= cntt ; i+=2 ) 41 { 42 for( int k = 1 ; k <= (cnttt - i) / 2 ; k++) 43 cout <<" " ; 44 45 for( int j = 1 ; j <= i ; j++) 46 cout << a ; 47 cout << endl ; 48 } 49 cout << n - temp << endl ; 50 return 0 ; 51 52 }
1 #include<iostream> 2 #include<cstring> 3 using namespace std ; 4 5 int main() 6 { 7 string n ; 8 cin >> n ; 9 int a[10]; 10 memset(a,0,sizeof(a)); 11 for( int i = 0 ; i < n.length() ; i++) 12 { 13 a[ n[i] - '0' ]++; 14 } 15 16 for( int i = 0 ; i <= 9 ; i++) 17 { 18 if( a[i] != 0 ) 19 cout << i <<":" << a[i] << endl ; 20 } 21 22 return 0 ; 23 }
1 #include<cstdio> 2 #include<cstdlib> 3 #include<iostream> 4 using namespace std ; 5 int main() 6 { 7 int F ; 8 cin >> F ; 9 cout << "Celsius = " << 5*(F-32)/9 << endl ; 10 return 0 ; 11 }
1 #include<iostream> 2 using namespace std ; 3 4 struct { 5 string s ; 6 int a , b ; 7 } a[1010]; 8 9 int main() 10 { 11 int n ; 12 cin >> n ; 13 for( int i = 1 ; i <= n ; i++) 14 cin >> a[i].s >> a[i].a >> a[i].b ; 15 int m ; 16 cin >> m ; 17 for( int i = 1 ; i <= m ; i++) 18 { 19 int temp ; 20 cin >> temp ; 21 for( int i = 1 ; i<= n ; i++) 22 { 23 if( a[i].a == temp ) 24 { 25 cout << a[i].s << ' ' << a[i].b <<endl ; 26 break ; 27 } 28 } 29 } 30 return 0 ; 31 }
1 #include<iostream> 2 #include<cstdio> 3 #include<cstdlib> 4 #include<algorithm> 5 #include<cmath> 6 using namespace std ; 7 8 bool is_prime( long long int n ) 9 { 10 if( n == 2 ) 11 return true ; 12 int temp = sqrt(n); 13 for( int j = 2 ; j <= temp ; j++) 14 if( n % j == 0 ) 15 return false ; 16 return true ; 17 } 18 int main() 19 { 20 long long n ; 21 cin >> n ; 22 int l = 0 , r = 0 , cnt = 0 ; 23 if( is_prime(n)) 24 { 25 cout << 1 << endl ; 26 cout << n << endl ; 27 return 0 ; 28 } 29 for( int i = 2 ; i <= 30 ; i++) 30 { 31 int temp = i; 32 int temp_cnt = 0 ; 33 int temp_chengfa = 1 ; 34 long long int nn = n ; 35 while( nn % temp == 0 ) 36 { 37 temp_chengfa *= temp ; 38 nn /= temp ; 39 temp_cnt++ ; 40 temp++; 41 42 43 } 44 if( temp_cnt > cnt && ( n % temp_chengfa == 0 ) ) 45 cnt = temp_cnt , l = i , r = temp-1 ; 46 continue ; 47 48 } 49 50 cout << cnt << endl ; 51 for( int i = l ; i <= r ; i++) 52 { 53 if( i == l ) 54 cout << i ; 55 else 56 cout << "*" << i ; 57 } 58 cout << endl ; 59 return 0 ; 60 }
1 #include<cstdio> 2 #include<iostream> 3 #include<cstring> 4 #include<iostream> 5 using namespace std ; 6 const string NAME[] ={"ling","yi","er","san","si","wu","liu","qi","ba","jiu"}; 7 8 int main() 9 { 10 string s ; 11 cin >> s ; 12 for( int i = 0 ; i < s.length() ; i++) 13 { 14 if( s[i] == '-' ) 15 cout << "fu"; 16 else 17 cout << NAME[s[i] -'0'] ; 18 if( i != s.length() - 1) 19 cout << ' ' ; 20 } 21 cout << endl; 22 return 0 ; 23 }
1 #include<iostream> 2 #include<cstdio> 3 #include<cstdlib> 4 #include<algorithm> 5 using namespace std ; 6 7 int main() 8 { 9 int a , b ; 10 cin >> a >> b ; 11 if( a > b ) 12 swap(a,b); 13 int sum = 0 ; 14 int cnt = 0 ; 15 for( int i = a ; i <= b ; i++) 16 { 17 printf("%5d",i); 18 cnt++; 19 if(cnt == 5 || i == b ) 20 { 21 cnt = 0 ; 22 printf("\n"); 23 } 24 25 sum+=i; 26 } 27 28 cout << "Sum = " << sum << endl ; 29 return 0 ; 30 31 }
1 #include<bits/stdc++.h> 2 using namespace std ; 3 //存储分数 4 struct fraction 5 { 6 long long numerator; 7 long long denominator; 8 }; 9 //求最大公约数,通分用 10 long long gcd( long long a , long long b ) 11 { 12 if ( a < 0 || b < 0 ) 13 a=abs(a),b=abs(b); 14 if( b == 0 ) 15 return a ; 16 else 17 return gcd( b , a % b ); 18 } 19 //分数加法,加后是个假分数形式(把b加到a上) 20 void add( struct fraction &a , struct fraction &b ) 21 { 22 a.numerator = a.numerator * b.denominator; 23 b.numerator = b.numerator * a.denominator ; 24 a.denominator = a.denominator * b.denominator ; 25 a.numerator = a.numerator + b.numerator ; 26 long long temp = gcd( a.numerator , a.denominator ); 27 a.numerator /= temp , a.denominator /= temp ; 28 return ; 29 } 30 31 int main() 32 { 33 struct fraction a , b ; 34 long long n ; 35 cin >> n ; 36 scanf("%lld/%lld",&a.numerator,&a.denominator); 37 long long intger = 0 ; 38 for( int i = 2 ; i <= n ; i++) 39 { 40 scanf("%lld/%lld",&b.numerator,&b.denominator); 41 add(a,b); 42 } 43 //通分 44 if( abs(a.numerator )>= a.denominator ) 45 { 46 intger = a.numerator / a.denominator ; 47 a.numerator = abs(a.numerator); 48 a.numerator %= a.denominator ; 49 } 50 51 //输出 52 if( intger == 0 && a.numerator == 0 ) 53 { 54 cout << 0 ; 55 } 56 else if ( intger != 0 && a.numerator == 0 ) 57 cout << intger ; 58 else if( intger != 0 ) 59 cout << intger << ' '; 60 if( a.numerator != 0 ) 61 printf("%lld/%lld",a.numerator,a.denominator); 62 cout << endl ; 63 return 0; 64 }
1 #include<bits/stdc++.h> 2 using namespace std ; 3 int a[3] ; 4 int main() 5 { 6 cin >> a[0] >> a[1] >> a[2] ; 7 sort(a,a+3); 8 printf("%d->%d->%d\n",a[0],a[1],a[2]); 9 return 0 ; 10 }
1 #include<bits/stdc++.h> 2 using namespace std ; 3 map<char,int> a ; 4 int main() 5 { 6 ios::sync_with_stdio(false); 7 string s1,s2; 8 getline(cin,s1); 9 getline(cin,s2); 10 for( int i = 0 ; i < s2.length() ; i++) 11 { 12 a[s2[i]] = 1 ; 13 } 14 15 for( int i = 0 ; i < s1.length() ; i++) 16 { 17 if( a[ s1[i] ] == 1 ) 18 s1[i] = 0 ; 19 } 20 21 for( int i = 0 ; i < s1.length() ; i++) 22 if( s1[i] != 0 ) 23 cout << s1[i] ; 24 cout << endl ; 25 return 0 ; 26 }
1 #include<bits/stdc++.h> 2 using namespace std ; 3 4 int main() 5 { 6 int n ; 7 cin >> n ; 8 printf("2^%d = %d",n,(int)pow(2,n)); 9 return 0 ; 10 }
1 #include<bits/stdc++.h> 2 using namespace std ; 3 4 int fun1( int n ) 5 { 6 if( n == 1 || n == 0 ) 7 return 1; 8 else 9 return n*fun1(n-1); 10 } 11 12 int fun2( int n ) 13 { 14 int ans = 0; 15 for( int i = 1 ; i <= n ; i++) 16 ans+= fun1(i); 17 return ans ; 18 } 19 20 int main() 21 { 22 int n ; 23 cin >> n ; 24 cout << fun2(n) << endl ; 25 return 0 ; 26 }
1 #include<bits/stdc++.h> 2 using namespace std ; 3 int main() 4 { 5 cout << "This is a simple problem." << endl ; 6 return 0 ; 7 }
1 #include<bits/stdc++.h> 2 using namespace std ; 3 4 void printf_line( char c, int n ) 5 { 6 for( int i = 1 ; i <= n ; i++) 7 cout << c ; 8 cout << endl ; 9 return ; 10 } 11 12 int main() 13 { 14 int n ; 15 char c ; 16 cin >> n >> c ; 17 for( int i = 1 ; i <= (n+1) >> 1 ; i++) 18 printf_line(c,n); 19 return 0 ; 20 } 21
1 #include<bits/stdc++.h> 2 using namespace std ; 3 int a[] = {0,7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2}; 4 int Z[] = {1,0,999,9,8,7,6,5,4,3,2}; 5 int calculate_key( string s ) 6 { 7 int ans = 0 ; 8 for( int i = 0 ; i < 17 ; i++) 9 ans+= (s[i] - '0' ) * a[i+1] ; 10 return (ans % 11 ); 11 } 12 13 bool judge( int a , int b ) 14 { 15 if( Z[a] == 999 && b == 'X' - '0' ) 16 return true ; 17 else if( Z[a] == b ) 18 return true ; 19 else 20 return false ; 21 } 22 23 int main() 24 { 25 ios::sync_with_stdio(false); 26 int n ; 27 string s ; 28 cin >> n ; 29 bool flag = true ; 30 for( int i = 1 ; i <= n ; i++) 31 { 32 cin >> s ; 33 int key = calculate_key(s); 34 if( !judge(key,s[17]-'0' )) 35 { 36 flag=false; 37 cout << s << endl ; 38 } 39 else 40 continue ; 41 } 42 if( flag ) 43 cout << "All passed" << endl ; 44 return 0 ; 45 }
1 #include<bits/stdc++.h> 2 using namespace std ; 3 4 int main() 5 { 6 string s ; 7 cin >> s ; 8 int flag1 = true ; // + - 9 int flag2 = false; // dan shuang . 10 int cnt = 0 ; 11 if( s[0] == '-' ) 12 flag1 = false ; 13 if( (s[ s.length() - 1 ] - '0' ) % 2 == 0 ) 14 flag2 = true ; 15 for( int i = 0 ; i < s.length() ; i++) 16 if( s[i] == '2' ) 17 cnt++; 18 printf("%.2lf\%\n",(double)cnt/(( (int) s.length() - ( flag1==false ? 1 : 0 ) ))*( flag1==false ? 1.5 : 1 )*(flag2==true ? 2 : 1 )*100 ) ; 19 return 0 ; 20 }
1 #include<bits/stdc++.h> 2 using namespace std ; 3 4 void printf_Dang( int n ) 5 { 6 for( int i = 1 ; i <= n ; i++) 7 cout << "Dang" ; 8 cout << endl; 9 return ; 10 } 11 12 int main() 13 { 14 int h , m ; 15 scanf("%d:%d",&h,&m); 16 if( h >= 0 && h <= 12 ) 17 { 18 if( h == 12 && m != 0 ) 19 printf_Dang( 1 ) ; 20 printf("Only %02d:%02d. Too early to Dang.\n",h,m); 21 } 22 else 23 { 24 if( m == 0 ) 25 printf_Dang( (h>12) ? (h-12) : h ) ; 26 else 27 printf_Dang((h > 12 ) ? ( h - 12 + 1 ) : (h+1)); 28 } 29 return 0 ; 30 }
1 #include<bits/stdc++.h> 2 using namespace std ; 3 int main() 4 { 5 int jia,yi; 6 cin >> jia >> yi ; 7 int n ; 8 cin >> n ; 9 int cntjia = 0 , cntyi = 0 ; 10 for( int i = 1; i <= n ; i++) 11 { 12 int jiahan,jiahua,yihan,yihua ; 13 cin >> jiahan >> jiahua >> yihan >> yihua ; 14 if( ( jiahan + yihan ) == jiahua && (jiahan + yihan) == yihua ) 15 continue ; 16 else if( (jiahan + yihan) == jiahua ) 17 { 18 jia--; 19 cntjia++; 20 } 21 else if( ( jiahan + yihan ) == yihua) 22 { 23 yi--; 24 cntyi++; 25 } 26 27 if( jia == -1) 28 { 29 cout << "A" << endl ; 30 cout << cntyi << endl ; 31 break ; 32 } 33 else if( yi == -1 ) 34 { 35 cout << "B" << endl ; 36 cout << cntjia << endl ; 37 break ; 38 } 39 } 40 41 return 0 ; 42 } 43 44
1 #include<bits/stdc++.h> 2 using namespace std ; 3 int a[100000]; 4 5 int main() 6 { 7 int n ; 8 cin >> n ; 9 memset(a,0,sizeof(a)); 10 for( int i = 1 ; i <= n ; i++) 11 { 12 int nn , data ; 13 cin >> nn; 14 if( nn == 1 ) 15 { 16 cin >> data ; 17 continue ; 18 } 19 else 20 { 21 for( int j = 1 ; j <= nn ; j++) 22 { 23 cin >> data ; 24 a[data]++; 25 } 26 } 27 } 28 29 int flag = true ; 30 int nnn ; 31 cin >> nnn ; 32 for( int i = 1 ; i <= nnn ; i++) 33 { 34 int temp ; 35 cin >> temp ; 36 if( a[temp] == 0 && flag ) 37 { 38 flag = false ; 39 //cout << temp; 40 printf("%05d",temp); 41 a[temp] = 1 ; 42 } 43 else if( a[temp] == 0 && (!flag) ) 44 { 45 //cout << ' ' << temp ; 46 printf(" %05d",temp); 47 a[temp] = 1 ; 48 } 49 50 51 } 52 if( !flag ) 53 cout << endl ; 54 else 55 cout << "No one is handsome" << endl ; 56 return 0 ; 57 }
1 #include<bits/stdc++.h> 2 using namespace std ; 3 int main() 4 { 5 cout << "I'm gonna WIN!" << endl ; 6 cout << "I'm gonna WIN!" << endl ; 7 cout << "I'm gonna WIN!" << endl ; 8 return 0 ; 9 }
1 #include<bits/stdc++.h> 2 using namespace std ; 3 int main() 4 { 5 int n ; 6 cin >> n ; 7 int odd = 0 , even = 0 ; 8 for( int i = 1 ; i <= n ; i++) 9 { 10 int temp ; 11 cin >> temp ; 12 if( temp % 2 == 0 ) 13 even++; 14 else 15 odd++; 16 } 17 18 cout << odd << ' ' << even << endl ; 19 return 0 ; 20 }
1 #include<bits/stdc++.h> 2 using namespace std ; 3 string s ; 4 void p( int n ) 5 { 6 for( int i = 1 ; i <= n ; i++) 7 { 8 cout << "GPLT" ; 9 } 10 return ; 11 } 12 int main() 13 { 14 cin >> s ; 15 int G = 0 , L = 0 , P = 0 , T = 0 ; 16 for( int i = 0 ; i < s.length() ; i++) 17 { 18 if( s[i] == 'G' || s[i] == 'g' ) 19 G++; 20 if ( s[i] == 'L' || s[i] == 'l' ) 21 L++; 22 if( s[i] == 'P' || s[i] == 'p' ) 23 P++; 24 if( s[i] == 'T' || s[i] == 't' ) 25 T++; 26 } 27 while( G != 0 || L != 0 || P != 0 || T != 0 ) 28 { 29 if( G != 0) 30 { 31 cout << "G"; 32 G--; 33 } 34 if( P != 0 ) 35 { 36 cout << "P"; 37 P--; 38 } 39 if( L != 0 ) 40 { 41 cout << "L"; 42 L--; 43 } 44 if( T != 0 ) 45 { 46 cout << "T"; 47 T--; 48 } 49 } 50 51 cout << endl ; 52 return 0 ; 53 }
1 #include<bits/stdc++.h> 2 using namespace std ; 3 4 int main() 5 { 6 int n ; 7 cin >> n ; 8 cout << (( n + 2 <=7 ) ? ( n + 2 ) : ( ( n + 2 ) % 7 )) << endl ; 9 return 0 ; 10 }
#include<bits/stdc++.h> using namespace std ; int fun( const string &s) { int ans = 0; for( int i = 0 ; i < s.length(); i++) { if( s[i] >= '0' && s[i] <= '9' ) ans= ( s[i] - '0' ) + ans * 10 ; else return -1; } if( ans > 1000 || ans < 1 ) return -1 ; return ans ; } int main() { string s1 , s2 ; getline(cin,s1,' '); getline(cin,s2); int n1 = fun(s1) , n2 = fun(s2); if( n1 == -1) printf("?"); else printf("%d",n1); printf(" + "); if( n2 == -1) printf("?"); else printf("%d",n2); printf(" = "); if( n1 == -1 || n2 == -1 ) printf("?\n"); else printf("%d\n",n1+n2); return 0 ; }
1 #include<bits/stdc++.h> 2 using namespace std ; 3 int main() 4 { 5 printf("I\n \nL\no\nv\ne\n \nG\nP\nL\nT\n"); 6 return 0 ; 7 }
1 #include<bits/stdc++.h> 2 using namespace std ; 3 int arr[100],ind[100]; 4 int numb[100]; 5 int te[10]; 6 7 bool cmp( int a , int b ) 8 { 9 return a > b ; 10 } 11 12 int main() 13 { 14 15 int tem = 0 ; 16 string s ; 17 cin >> s ; 18 19 for( int i = 0 ; i < 11 ; i++) 20 { 21 numb[i] = s[i] - '0' ; 22 te[numb[i]]++; 23 } 24 25 for( int i = 9 ; i >= 0 ; i-- ) 26 { 27 if( te[i] != 0 ) 28 arr[tem++] = i ; 29 } 30 31 for( int i = 0 ; i < 11 ; i++) 32 { 33 for( int j = 0 ; j <= 9 ; j++) 34 { 35 if( numb[i] == arr[j] ) 36 { 37 ind[i] = j ; 38 break; 39 } 40 41 } 42 } 43 44 printf("int[] arr = new int[]{%d",arr[0]); 45 for( int i = 1 ; i < tem ; i++) 46 cout << ',' << arr[i] ; 47 cout << "};" << endl ; 48 printf("int[] index = new int[]{%d",ind[0]); 49 for( int i = 1 ; i < 11 ; i++) 50 cout << ',' << ind[i] ; 51 cout << "};" << endl ; 52 return 0 ; 53 }
1 #include<bits/stdc++.h> 2 using namespace std ; 3 bool isprime( int n ) 4 { 5 if( n == 1 ) 6 return false ; 7 if( n == 2 ) 8 return true ; 9 for( int i = 2 ; i <= sqrt(n) ; i++) 10 { 11 if( n % i == 0 ) 12 return false ; 13 } 14 15 return true ; 16 } 17 18 int main() 19 { 20 int n ; 21 cin >> n ; 22 for( int i = 1 ; i <= n ; i ++) 23 { 24 int number ; 25 cin >> number ; 26 if( isprime(number)) 27 cout << "Yes" << endl ; 28 else 29 cout << "No" << endl ; 30 } 31 32 return 0 ; 33 }
1 #include<bits/stdc++.h> 2 using namespace std ; 3 double fun( int n ) 4 { 5 return (n-100) * 0.9 *2 ; 6 } 7 8 int main() 9 { 10 int h ; 11 cin >> h ; 12 printf("%.1lf\n",fun(h)); 13 return 0 ; 14 }
1 #include<bits/stdc++.h> 2 using namespace std ; 3 4 struct student 5 { 6 int sex ; 7 string name ; 8 int rank ; 9 }a[55]; 10 11 void deletee( struct student &a) 12 { 13 a.sex = -1; 14 a.name.clear(); 15 a.rank = 0 ; 16 return ; 17 } 18 19 20 int main() 21 { 22 int n ; 23 cin >> n ; 24 for( int i = 1 ; i <= n ; i++) 25 { 26 cin >> a[i].sex >> a[i].name ; 27 a[i].rank = i; 28 } 29 30 for( int i = 1 ; i <= n ; i++) 31 { 32 bool flag = false ; ; 33 if( !a[i].name.empty()) 34 { 35 cout << a[i].name << ' '; 36 flag = true ; 37 } 38 39 if( a[i].sex == 0 ) 40 { 41 for( int j = n ; j>=1 ; j--) 42 { 43 if( a[j].sex == 1 ) 44 { 45 cout << a[j].name ; 46 deletee(a[j]); 47 break; 48 } 49 } 50 } 51 else if( a[i].sex == 1 ) 52 { 53 for( int j = n ; j >= 1 ; j--) 54 { 55 if( a[j].sex == 0 ) 56 { 57 cout << a[j].name ; 58 deletee(a[j]); 59 break ; 60 61 } 62 } 63 } 64 if(flag) 65 cout << endl ; 66 } 67 return 0 ; 68 }
1 #include<bits/stdc++.h> 2 using namespace std ; 3 const string s[] = {"You are wan mei!","You are tai shou le!","You are tai pang le!" } ; 4 5 int fun( int h , int w ) 6 { 7 double standard_w = (h - 100 ) * 0.9 * 2 ; 8 if( fabs( standard_w - w ) < standard_w * 0.1 ) 9 return 0 ; 10 else if( standard_w > w ) 11 return 1; 12 else 13 return 2 ; 14 } 15 16 int main() 17 { 18 int n ; 19 cin >> n ; 20 for( int i = 1 ; i <= n ; i++) 21 { 22 int a , b ; 23 cin >> a >> b ; 24 cout << s[fun(a,b)] << endl ; 25 } 26 return 0 ; 27 }
1 #include<bits/stdc++.h> 2 using namespace std ; 3 string s ; 4 string a ; 5 6 void _printf( int n , string m ) 7 { 8 if( n > s.length() - 1 ) 9 { 10 for( int i = 0 ; i < ( n - s.length() ) ; i++) 11 cout << m ; 12 cout << s << endl ; 13 } 14 else 15 { 16 for( int i = s.length() - n ; i < s.length() ; i++) 17 { 18 cout << s[i] ; 19 } 20 cout << endl ; 21 } 22 23 return ; 24 } 25 26 int main() 27 { 28 int n; 29 cin >> n >> a ; 30 getchar(); 31 getline(cin,s); 32 _printf(n,a); 33 return 0 ; 34 } 35 36 37
浙公网安备 33010602011771号