Acwing PATA 打卡记录
第一章 字符串模拟
1.PATA 1001 A + B 格式
# include <bits/stdc++.h>
using namespace std;
int main ( ) {
int a, b, sum;
cin>> a>> b;
sum= a+ b;
string str= to_string ( sum) ;
string ans;
int j= 0 ;
if ( sum== 0 ) printf ( "0" ) ;
else {
for ( int i= str. size ( ) - 1 ; i>= 0 ; i-- ) {
ans= str[ i] + ans;
j++ ;
if ( j% 3 == 0 && i!= 0 && str[ i- 1 ] != '-' ) ans= ',' + ans;
}
cout<< ans<< endl;
}
return 0 ;
}
2.PATA 1005 拼写正确
# include <bits/stdc++.h>
using namespace std;
char num[ 10 ] [ 10 ] = { "zero" , "one" , "two" , "three" , "four" , "five" , "six" , "seven" , "eight" , "nine" } ;
int s[ 100 ] ;
int main ( ) {
string str;
cin>> str;
int sum= 0 ;
for ( int i= 0 ; i< str. size ( ) ; i++ ) {
sum+= str[ i] - '0' ;
}
int j= 0 ;
if ( sum== 0 ) printf ( "zero" ) ;
else {
while ( sum) {
s[ j++ ] = sum% 10 ;
sum/= 10 ;
}
for ( int k= j- 1 ; k>= 0 ; k-- ) {
printf ( "%s " , num[ s[ k] ] ) ;
}
}
return 0 ;
}
3.PATA 1006 签到与签出
# include <bits/stdc++.h>
using namespace std;
struct stu {
string id;
string open_time;
string close_time;
} ;
stu s[ 20 ] ;
string maxn= "00:00:00" ;
string minn= "24:00:00" ;
int maxi, mini;
int main ( ) {
int n;
cin>> n;
for ( int i= 0 ; i< n; i++ ) {
cin>> s[ i] . id>> s[ i] . open_time>> s[ i] . close_time;
}
for ( int i= 0 ; i< n; i++ ) {
if ( s[ i] . open_time< minn) {
minn= s[ i] . open_time;
mini= i;
}
if ( s[ i] . close_time> maxn) {
maxn= s[ i] . close_time;
maxi= i;
}
}
cout<< s[ mini] . id<< ' ' << s[ maxi] . id;
return 0 ;
}
4.PATA 1035 密码
# include <bits/stdc++.h>
using namespace std;
struct stu {
string id;
string pwd;
} ;
stu s1[ 1010 ] , s2[ 1010 ] ;
int flag;
int main ( ) {
int n;
int k= 0 ;
cin>> n;
for ( int i= 0 ; i< n; i++ ) {
cin>> s1[ i] . id>> s1[ i] . pwd;
}
for ( int i= 0 ; i< n; i++ ) {
for ( int j= 0 ; j< s1[ i] . pwd. size ( ) ; j++ ) {
if ( s1[ i] . pwd[ j] == '1' ) {
s1[ i] . pwd[ j] = '@' ;
flag= 1 ;
}
if ( s1[ i] . pwd[ j] == '0' ) {
s1[ i] . pwd[ j] = '%' ;
flag= 1 ;
}
if ( s1[ i] . pwd[ j] == 'l' ) {
s1[ i] . pwd[ j] = 'L' ;
flag= 1 ;
}
if ( s1[ i] . pwd[ j] == 'O' ) {
s1[ i] . pwd[ j] = 'o' ;
flag= 1 ;
}
}
if ( flag) {
s2[ k++ ] = s1[ i] ;
}
flag= 0 ;
}
if ( ! k) {
if ( n== 1 ) printf ( "There is 1 account and no account is modified" ) ;
else {
printf ( "There are %d accounts and no account is modified" , n) ;
}
}
else {
printf ( "%d\n" , k) ;
for ( int i= 0 ; i< k; i++ )
cout<< s2[ i] . id<< ' ' << s2[ i] . pwd<< endl;
}
return 0 ;
}
5.PATA 1036 男孩 vs 女孩
# include <bits/stdc++.h>
using namespace std;
const int N= 105 ;
struct stu {
char name[ 20 ] ;
char sex;
char num[ 20 ] ;
int score;
} ;
int cntf, cntm;
int maxf, minm;
int maxi, mini;
struct stu s[ N] ;
int main ( ) {
int n;
cin>> n;
maxf= - 1 ;
minm= 101 ;
for ( int i= 0 ; i< n; i++ ) {
cin>> s[ i] . name>> s[ i] . sex>> s[ i] . num>> s[ i] . score;
if ( s[ i] . sex== 'F' ) {
cntf++ ;
if ( s[ i] . score> maxf) {
maxf= s[ i] . score;
maxi= i;
}
}
else if ( s[ i] . sex== 'M' ) {
cntm++ ;
if ( s[ i] . score< minm) {
minm= s[ i] . score;
mini= i;
}
}
}
if ( cntf) {
printf ( "%s %s\n" , s[ maxi] . name, s[ maxi] . num) ;
} else {
printf ( "Absent\n" ) ;
}
if ( cntm) {
printf ( "%s %s\n" , s[ mini] . name, s[ mini] . num) ;
} else {
printf ( "Absent\n" ) ;
}
if ( cntm&& cntf) {
printf ( "%d" , maxf- minm) ;
} else {
printf ( "NA" ) ;
}
}
6.PATA 1050 字符串减法
# include <bits/stdc++.h>
using namespace std;
const int N= 1e4 + 10 ;
int vis1[ N] , vis2[ N] ;
int main ( ) {
string a, b;
getline ( cin, a) ;
getline ( cin, b) ;
for ( int i= 0 ; i< a. size ( ) ; i++ ) {
vis1[ a[ i] ] = 1 ;
}
for ( int i= 0 ; i< b. size ( ) ; i++ ) {
vis2[ b[ i] ] = 1 ;
}
for ( int i= 0 ; i< a. size ( ) ; i++ ) {
if ( vis1[ a[ i] ] == 1 && vis2[ a[ i] ] == 0 ) {
printf ( "%c" , a[ i] ) ;
}
}
return 0 ;
}
7.PATA 1071 说话方式
# include <bits/stdc++.h>
using namespace std;
bool check ( char c) {
if ( c>= '0' && c<= '9' ) return true ;
if ( c>= 'a' && c<= 'z' ) return true ;
if ( c>= 'A' && c<= 'Z' ) return true ;
return false ;
}
map< string, int > cnt;
int main ( ) {
string str;
getline ( cin, str) ;
for ( int i= 0 ; i< str. size ( ) ; i++ ) {
if ( check ( str[ i] ) ) {
int j= i;
string word;
while ( check ( str[ j] ) && j< str. size ( ) ) word+= tolower ( str[ j++ ] ) ;
i= j;
cnt[ word] ++ ;
}
}
string ans;
int maxn= - 1 ;
for ( auto it : cnt) {
if ( it. second> maxn|| it. second== maxn&& it. first< ans) {
ans= it. first;
maxn= it. second;
}
}
cout<< ans<< ' ' << maxn<< endl;
return 0 ;
}
8.PATA 1061 约会
# include <bits/stdc++.h>
using namespace std;
char weekday[ 10 ] [ 10 ] = { "MON" , "TUE" , "WED" , "THU" , "FRI" , "SAT" , "SUN" } ;
int flag, flag2= 0 ;
int d, h, m;
bool check ( char c) {
if ( c>= 'a' && c<= 'z' ) return true ;
if ( c>= 'A' && c<= 'Z' ) return true ;
return false ;
}
int main ( ) {
string s1, s2, s3, s4;
cin>> s1>> s2>> s3>> s4;
for ( int i= 0 ; i< s1. size ( ) && i< s2. size ( ) ; i++ ) {
if ( s1[ i] == s2[ i] && s1[ i] >= 'A' && s1[ i] <= 'G' && flag== 0 ) {
d= s1[ i] - 'A' ;
i++ ;
flag= 1 ;
}
if ( flag2== 0 && flag== 1 && s1[ i] == s2[ i] ) {
if ( s1[ i] >= '0' && s1[ i] <= '9' ) {
h= s1[ i] - '0' ;
flag2= 1 ;
} else if ( s1[ i] >= 'A' && s1[ i] <= 'N' ) {
h= s1[ i] - 'A' + 10 ;
flag2= 1 ;
}
}
}
for ( int i= 0 ; i< s3. size ( ) && i< s4. size ( ) ; i++ ) {
if ( s3[ i] == s4[ i] && check ( s3[ i] ) ) {
m= i;
break ;
}
}
printf ( "%s %02d:%02d" , weekday[ d] , h, m) ;
return 0 ;
}
9.PATA 1016 电话账单
# include <bits/stdc++.h>
using namespace std;
struct record {
int d, h, m, month;
int t;
string state;
} ;
record t;
map< string, vector< record>> m;
double price[ 30 ] ;
bool cmp ( record a, record b) {
if ( a. d!= b. d) return a. d< b. d;
else if ( a. h!= b. h) return a. h< b. h;
else if ( a. m!= b. m) return a. m< b. m;
}
int main ( ) {
int n, month, i;
int sum= 0 ;
char name[ 100 ] ;
char state[ 100 ] ;
for ( int i= 0 ; i< 24 ; i++ ) {
cin>> price[ i] ;
sum+= price[ i] * 60 ;
}
cin>> n;
for ( int i= 0 ; i< n; i++ ) {
char c;
int day, hour, minute;
cin>> name>> month>> c>> day>> c>> hour>> c>> minute>> state;
t. d= day;
t. h= hour;
t. m= minute;
t. state= state;
t. month= month;
t. t= day* 1440 + hour* 60 + minute;
m[ name] . emplace_back ( t) ;
}
for ( auto it= m. begin ( ) ; it!= m. end ( ) ; it++ ) {
auto v= it-> second;
sort ( v. begin ( ) , v. end ( ) , cmp) ;
double total= 0 ;
for ( i= 0 ; i< v. size ( ) ; ) {
if ( i+ 1 < v. size ( ) && v[ i] . state== "on-line" && v[ i+ 1 ] . state== "off-line" ) {
if ( ! total) {
cout<< it-> first;
printf ( " " ) ;
printf ( "%02d\n" , month) ;
}
double money= 0 ;
int t1= v[ i] . t;
int t2= v[ i+ 1 ] . t;
for ( int Time= t1; Time< t2; Time++ ) {
money+= price[ Time% 1440 / 60 ] ;
}
total+= money;
int sub= ( v[ i+ 1 ] . d- v[ i] . d) * 1440 + ( v[ i+ 1 ] . h- v[ i] . h) * 60 + v[ i+ 1 ] . m- v[ i] . m;
printf ( "%02d:%02d:%02d %02d:%02d:%02d %d $%.2f\n" , v[ i] . d, v[ i] . h, v[ i] . m, v[ i+ 1 ] . d, v[ i+ 1 ] . h, v[ i+ 1 ] . m, sub, money/ 100.0 ) ;
i+= 2 ;
} else {
i++ ;
}
}
if ( total) printf ( "Total amount: $%.2f\n" , total/ 100.0 ) ;
}
return 0 ;
}
10.PATA 1017 银行排队
# include <bits/stdc++.h>
using namespace std;
const int N= 10010 ;
struct persons {
int arrive_time;
int service_time;
} ;
persons p[ N] ;
bool cmp ( persons a, persons b) {
return a. arrive_time< b. arrive_time;
}
int main ( ) {
int n, k;
cin>> n>> k;
for ( int i= 0 ; i< n; i++ ) {
int hour, minute, second, servic_time;
scanf ( "%d:%d:%d %d" , & hour, & minute, & second, & servic_time) ;
p[ i] . arrive_time= hour* 3600 + minute* 60 + second;
p[ i] . service_time= min ( servic_time, 60 ) * 60 ;
}
sort ( p, p+ n, cmp) ;
priority_queue< int , vector< int > , greater< int >> window;
int sum= 0 ;
int cnt= 0 ;
for ( int i= 0 ; i< k; i++ ) window. push ( 8 * 3600 ) ;
for ( int i= 0 ; i< n; i++ ) {
auto t= p[ i] ;
int w= window. top ( ) ;
window. pop ( ) ;
if ( t. arrive_time> 17 * 3600 ) break ;
int start_time= max ( t. arrive_time, w) ;
sum+= - t. arrive_time+ start_time;
cnt++ ;
window. push ( start_time+ t. service_time) ;
}
printf ( "%.1f" , sum* 1.0 / cnt/ 60 ) ;
return 0 ;
}
11.PATA 1026 乒乓球(好家伙 不会QAQ)
12.PATA 1060 它们是否相等
# include <bits/stdc++.h>
using namespace std;
string change ( string a, int n) {
int k= a. find ( "." ) ;
if ( k== - 1 ) {
a+= "." ;
k= a. find ( "." ) ;
}
string s= a. substr ( 0 , k) + a. substr ( k+ 1 ) ;
while ( s. size ( ) && s[ 0 ] == '0' ) {
s= s. substr ( 1 ) ;
k-- ;
}
if ( s. empty ( ) ) k= 0 ;
if ( s. size ( ) > n) s= s. substr ( 0 , n) ;
else s+= string ( n- s. size ( ) , '0' ) ;
return "0." + s+ "*10^" + to_string ( k) ;
}
int main ( ) {
int n;
string a, b;
cin>> n>> a>> b;
a= change ( a, n) ;
b= change ( b, n) ;
if ( a== b) {
cout<< "YES " << a<< endl;
} else {
cout<< "NO " << a<< ' ' << b<< endl;
}
return 0 ;
}
13.PATA 1073 科学计数法
# include <bits/stdc++.h>
using namespace std;
int main ( ) {
string s;
cin>> s;
if ( s[ 0 ] == '-' ) cout<< '-' ;
int k= s. find ( "E" ) ;
string a;
a= s[ 1 ] + s. substr ( 3 , k- 3 ) ;
int b= stoi ( s. substr ( k+ 1 ) ) ;
b++ ;
if ( b<= 0 ) a= "0." + string ( - b, '0' ) + a;
else if ( b>= a. size ( ) ) {
a+= string ( b- a. size ( ) , '0' ) ;
} else {
a= a. substr ( 0 , b) + '.' + a. substr ( b) ;
}
cout<< a<< endl;
return 0 ;
}
14.PATA 1077 Kuchiguse
# include <bits/stdc++.h>
using namespace std;
int min_len= 999 ;
int main ( ) {
int n, j;
cin>> n;
char c;
int ans= 0 ;
getchar ( ) ;
string a[ 1010 ] ;
for ( int i= 0 ; i< n; i++ ) {
getline ( cin, a[ i] ) ;
reverse ( a[ i] . begin ( ) , a[ i] . end ( ) ) ;
if ( a[ i] . size ( ) < min_len) {
min_len= a[ i] . size ( ) ;
}
}
for ( int i= 0 ; i< min_len; i++ ) {
c= a[ 0 ] [ i] ;
for ( j= 0 ; j< n; j++ ) {
if ( a[ j] [ i] != c) {
break ;
}
}
if ( j== n) {
ans++ ;
} else {
break ;
}
}
if ( ans) {
for ( int i= ans- 1 ; i>= 0 ; i-- )
printf ( "%c" , a[ 0 ] [ i] ) ;
} else {
cout<< "nai" << endl;
}
return 0 ;
}
15.PATA 1082 中文读数字
# include <iostream>
# include <string>
using namespace std;
string Dict[ ] = { "Ge" , "Shi" , "Bai" , "Qian" , "Wan" , "Yi" } ;
string Num[ ] = { "ling" , "yi" , "er" , "san" , "si" , "wu" , "liu" , "qi" , "ba" , "jiu" } ;
string converNum ( string str) {
string ans;
if ( str[ 0 ] == '0' ) {
return "ling" ;
}
if ( str[ 0 ] == '-' ) {
ans = "Fu " ;
str. erase ( 0 , 1 ) ;
}
int len = str. length ( ) ;
int i = 0 ;
while ( len) {
int zeroCnt = 0 ;
bool zero = false ;
for ( int j = ( len - 1 ) % 4 ; j >= 0 ; j-- ) {
int pos = str. length ( ) - len;
int num = str[ pos] - '0' ;
if ( num > 0 ) {
if ( zero) {
ans += "ling " ;
zero = false ;
}
ans += Num[ num] + ' ' ;
if ( j != 0 ) ans += Dict[ j] + ' ' ;
}
else {
zeroCnt++ ;
zero = true ;
}
len-- ;
}
if ( len / 4 > 0 && zeroCnt != 4 ) ans += Dict[ 3 + len / 4 ] + ' ' ;
}
ans. pop_back ( ) ;
return ans;
}
int main ( ) {
string str;
getline ( cin, str) ;
str = converNum ( str) ;
cout << str << endl;
return 0 ;
}
16.PATA 1084 坏掉的键盘
# include <bits/stdc++.h>
using namespace std;
char a[ 100 ] , b[ 100 ] ;
int vis[ 200 ] ;
int main ( ) {
cin>> a;
cin>> b;
int i, j;
char c1, c2;
for ( i= 0 ; i< strlen ( a) ; i++ ) {
for ( j= 0 ; j< strlen ( b) ; j++ ) {
c1= a[ i] ;
c2= b[ j] ;
if ( c1>= 'a' && c1<= 'z' ) c1-= 32 ;
if ( c2>= 'a' && c2<= 'z' ) c2-= 32 ;
if ( c1== c2) break ;
}
if ( j== strlen ( b) && vis[ c1] == 0 ) {
vis[ c1] = 1 ;
printf ( "%c" , c1) ;
}
}
return 0 ;
}
17.PATA 1108 求平均值
# include <bits/stdc++.h>
using namespace std;
double check ( string a) {
int cnti= 0 ;
int flag= 0 ;
for ( int i= 0 ; i< a. size ( ) ; i++ ) {
if ( a[ i] >= '0' && a[ i] <= '9' ) flag= 1 ;
if ( a[ i] != '.' && a[ i] != '-' && ( a[ i] < '0' || a[ i] > '9' ) ) return 1010 ;
if ( a[ i] == '.' ) {
for ( int j= i+ 1 ; j< a. size ( ) ; j++ ) {
if ( a[ j] == '.' ) return 1010 ;
if ( a[ j] >= '0' && a[ j] <= '9' ) cnti++ ;
}
}
if ( cnti> 2 ) return 1010 ;
}
if ( flag== 0 ) return 1010 ;
return atof ( a. c_str ( ) ) ;
}
double sum;
int cnt;
int main ( ) {
int n;
cin>> n;
string a[ 1010 ] ;
for ( int i= 0 ; i< n; i++ ) {
cin>> a[ i] ;
double b= check ( a[ i] ) ;
if ( b>= - 1000 && b<= 1000 ) {
sum+= b;
cnt++ ;
} else {
cout<< "ERROR: " + a[ i] + " is not a legal number" << endl;
}
}
if ( cnt== 0 ) {
printf ( "The average of 0 numbers is Undefined\n" ) ;
} else if ( cnt== 1 ) {
printf ( "The average of 1 number is %.2f" , sum* 1.0 / cnt) ;
} else {
printf ( "The average of %d numbers is %.2f" , cnt, sum* 1.0 / cnt) ;
}
return 0 ;
}
18.PATA 1124 微博转发抽奖
# include <bits/stdc++.h>
using namespace std;
map< string, int > mp;
int main ( ) {
int m, n, s;
cin>> m>> n>> s;
string a[ 1010 ] ;
for ( int i= 1 ; i<= m; i++ ) {
cin>> a[ i] ;
}
if ( s> m) printf ( "Keep going..." ) ;
for ( int i= s; i<= m; i+= n) {
if ( mp[ a[ i] ] == 0 ) {
cout<< a[ i] << endl;
mp[ a[ i] ] ++ ;
} else {
for ( int j= i+ 1 ; j<= m; j++ ) {
i++ ;
if ( mp[ a[ j] ] == 0 ) {
cout<< a[ j] << endl;
mp[ a[ j] ] ++ ;
break ;
}
}
}
}
return 0 ;
}
19.PATA 1141 PAT单位排行
# include <bits/stdc++.h>
using namespace std;
struct school {
string name;
int cnt;
int rank;
double sum;
} ;
school s;
string to_low ( string a) {
for ( int i= 0 ; i< a. size ( ) ; i++ ) {
if ( a[ i] >= 'A' && a[ i] <= 'Z' ) a[ i] += 32 ;
}
return a;
}
map< string, school> mp;
bool cmp ( school a, school b) {
if ( a. sum!= b. sum) return a. sum> b. sum;
else if ( a. cnt!= b. cnt) return a. cnt< b. cnt;
else return a. name< b. name;
}
int main ( ) {
int n;
cin>> n;
for ( int i= 0 ; i< n; i++ ) {
string id, sch_name;
double score;
cin>> id>> score>> sch_name;
sch_name= to_low ( sch_name) ;
if ( id[ 0 ] == 'B' ) score/= 1.5 ;
else if ( id[ 0 ] == 'T' ) score*= 1.5 ;
mp[ sch_name] . name= sch_name;
mp[ sch_name] . sum+= score;
mp[ sch_name] . cnt++ ;
}
cout<< mp. size ( ) << endl;
vector< school> v;
for ( auto it= mp. begin ( ) ; it!= mp. end ( ) ; it++ ) {
it-> second. sum= ( int ) ( it-> second. sum+ 1e-8 ) ;
v. emplace_back ( it-> second) ;
}
sort ( v. begin ( ) , v. end ( ) , cmp) ;
v[ 0 ] . rank= 1 ;
for ( int i= 1 ; i< v. size ( ) ; i++ ) {
if ( v[ i] . sum== v[ i- 1 ] . sum) {
v[ i] . rank= v[ i- 1 ] . rank;
} else {
v[ i] . rank= i+ 1 ;
}
}
for ( int i= 0 ; i< mp. size ( ) ; i++ ) {
cout<< v[ i] . rank<< ' ' << v[ i] . name<< ' ' << v[ i] . sum<< ' ' << v[ i] . cnt<< endl;
}
return 0 ;
}
20.PATA 1153 解码PAT准考证
# include <bits/stdc++.h>
using namespace std;
struct stu {
string id;
int score;
} ;
struct query {
int num;
string qu;
} ;
struct p {
int clas;
int cnt;
} ;
const int N= 1e4 + 10 ;
stu s[ N] ;
query q[ 110 ] ;
p w[ 1000 ] ;
int cnt1, cnt2, cnt3, cnt4;
bool cmp1 ( stu a, stu b) {
if ( a. score!= b. score) return a. score> b. score;
else return a. id< b. id;
}
bool cmp2 ( p a, p b) {
if ( a. cnt!= b. cnt) return a. cnt> b. cnt;
else return a. clas< b. clas;
}
int main ( ) {
int n, m;
cin>> n>> m;
for ( int i= 0 ; i< n; i++ ) {
cin>> s[ i] . id>> s[ i] . score;
}
for ( int i= 0 ; i< m; i++ ) {
for ( int i= 0 ; i< 1000 ; i++ )
w[ i] . cnt= 0 ;
cnt1= cnt2= cnt3= 0 ;
int k= i+ 1 ;
cin>> q[ i] . num>> q[ i] . qu;
vector< stu> v;
if ( q[ i] . num== 1 ) {
for ( int j= 0 ; j< n; j++ ) {
if ( s[ j] . id[ 0 ] == q[ i] . qu[ 0 ] ) {
v. push_back ( s[ j] ) ;
cnt1++ ;
}
}
sort ( v. begin ( ) , v. end ( ) , cmp1) ;
printf ( "Case %d: %d " , k, q[ i] . num) ;
cout<< q[ i] . qu<< endl;
if ( cnt1== 0 ) {
printf ( "NA\n" ) ;
} else {
for ( int i= 0 ; i< cnt1; i++ ) {
cout<< v[ i] . id<< " " << v[ i] . score<< endl;
}
}
} else if ( q[ i] . num== 2 ) {
printf ( "Case %d: %d " , k, q[ i] . num) ;
cout<< q[ i] . qu<< endl;
int sum= 0 ;
for ( int i= 0 ; i< n; i++ ) {
string b= s[ i] . id. substr ( 1 , 3 ) ;
if ( b== q[ k- 1 ] . qu) {
sum+= s[ i] . score;
cnt2++ ;
}
}
if ( cnt2== 0 ) printf ( "NA\n" ) ;
else {
cout<< cnt2<< " " << sum<< endl;
}
} else if ( q[ i] . num== 3 ) {
printf ( "Case %d: %d " , k, q[ i] . num) ;
cout<< q[ i] . qu<< endl;
for ( int i= 0 ; i< n; i++ ) {
string b= s[ i] . id. substr ( 4 , 6 ) ;
if ( b== q[ k- 1 ] . qu) {
cnt3++ ;
string c= s[ i] . id. substr ( 1 , 3 ) ;
int d= atoi ( c. c_str ( ) ) ;
w[ d] . clas= d;
w[ d] . cnt++ ;
}
}
if ( cnt3== 0 ) printf ( "NA\n" ) ;
else {
sort ( w, w+ 1000 , cmp2) ;
for ( int i= 0 ; i< 1000 ; i++ ) {
if ( w[ i] . cnt!= 0 ) {
printf ( "%d %d\n" , w[ i] . clas, w[ i] . cnt) ;
}
}
}
}
}
return 0 ;
}