1091 N-自守数 (15分)
#include <bits/stdc++.h>
using namespace std;
int main ( )
{
int n;
cin>> n;
while ( n-- )
{
int k;
int flag= 0 ;
int num;
cin >> k;
for ( int i= 1 ; i<= 9 ; i++ )
{
num= i* k* k;
string snum= to_string ( num) , sk= to_string ( k) ;
string smullend= snum. substr ( snum. size ( ) - sk. size ( ) ) ;
if ( smullend== sk)
{
flag= 1 ;
cout<< i<< ' ' << snum<< endl;
break ;
}
}
if ( ! flag)
cout<< "No" << endl;
}
return 0 ;
}
1092 最好吃的月饼 (20分)
#include <iostream>
#include <vector>
using namespace std;
vector< int > g[ 1000 ] ;
int sum[ 1000 ] ;
int mx= - 1 ;
int main ( )
{
int n, m;
cin>> n>> m;
for ( int i= 1 ; i<= m; i++ )
{
for ( int j= 1 ; j<= n; j++ )
{
int x;
cin>> x;
g[ i] . push_back ( x) ;
}
}
for ( int i= 0 ; i< n; i++ )
{
for ( int j= 1 ; j<= m; j++ )
{
sum[ i] + = g[ j] [ i] ;
mx= max ( mx, sum[ i] ) ;
}
}
cout<< mx<< endl;
int f= 0 ;
for ( int i= 0 ; i< n; i++ )
{
if ( sum[ i] == mx)
{
if ( f) cout<< " " ;
cout<< i+ 1 , f= 1 ;
}
}
return 0 ;
}
1093 字符串A+B (20分)
#include <iostream>
using namespace std;
int vis[ 250 ] ;
int main ( )
{
string a, b;
getline ( cin, a) ;
getline ( cin, b) ;
a = a + b;
for ( auto e : a)
{
if ( ! vis[ e] )
cout << e, vis[ e] = 1 ;
}
return 0 ;
}
1094 谷歌的招聘 (20分)
#include <bits/stdc++.h>
using namespace std;
bool isprim ( int x)
{
for ( int i= 2 ; i<= sqrt ( x) ; i++ )
{
if ( x% i== 0 )
return false ;
}
return true ;
}
int main ( )
{
int l, k;
string s;
cin>> l>> k;
getchar ( ) ;
getline ( cin, s) ;
for ( int i= 0 ; i<= l- k; i++ )
{
long long tmp= stoi ( s. substr ( i, k) ) ;
if ( isprim ( tmp) )
{
cout<< s. substr ( i, k) ;
return 0 ;
}
}
cout<< "404" << endl;
return 0 ;
}
1095 解码PAT准考证 (25分)
#include <bits/stdc++.h>
using namespace std;
struct stu
{
string id;
int score;
} test[ 10000 ] , temp[ 10000 ] ;
bool rule1 ( stu& a, stu& b)
{
return a. score != b. score ? a. score > b. score : a. id < b. id;
}
bool rule2 ( pair< string, int > & a, pair< string, int > & b)
{
return a. second != b. second ? a. second > b. second : a. first < b. first;
}
unordered_map< string, int > mp;
int main ( )
{
int N, M;
cin>> N>> M;
for ( int i= 0 ; i< N; i++ ) cin>> test[ i] . id>> test[ i] . score;
for ( int i= 1 ; i<= M; i++ )
{
int num;
string name;
cin>> num>> name;
printf ( "Case %d: %d %s\n" , i, num, name. c_str ( ) ) ;
if ( num== 1 )
{
int k= 0 ;
for ( int j= 0 ; j< N; j++ )
{
if ( test[ j] . id[ 0 ] == name[ 0 ] )
{
temp[ k++ ] = test[ j] ;
}
}
if ( k== 0 ) printf ( "NA\n" ) ;
else
{
sort ( temp, temp+ k, rule1) ;
for ( int j= 0 ; j< k; j++ )
{
printf ( "%s %d\n" , temp[ j] . id. c_str ( ) , temp[ j] . score) ;
}
}
}
else if ( num== 2 )
{
int cnt= 0 , sum= 0 ;
for ( int j= 0 ; j< N; j++ )
{
if ( test[ j] . id. substr ( 1 , 3 ) == name)
{
cnt++ ;
sum+ = test[ j] . score;
}
}
if ( cnt== 0 ) printf ( "NA\n" ) ;
else printf ( "%d %d\n" , cnt, sum) ;
}
else
{
mp. clear ( ) ;
for ( int j= 0 ; j< N; j++ )
{
if ( test[ j] . id. substr ( 4 , 6 ) == name)
{
mp[ test[ j] . id. substr ( 1 , 3 ) ] ++ ;
}
}
vector< pair< string, int >> v;
for ( auto e: mp) v. push_back ( e) ;
if ( v. size ( ) == 0 ) printf ( "NA\n" ) ;
else
{
sort ( v. begin ( ) , v. end ( ) , rule2) ;
for ( auto e : v)
{
printf ( "%s %d\n" , e. first. c_str ( ) , e. second) ;
}
}
}
}
return 0 ;
}