# PAT (Basic Level) Practise 1021 – 1025 解题报告

### 1021. 个位数统计 (15)

#include <map>
#include <iostream>
#include <string>

int main()
{
std::string strInput;
std::cin >> strInput;
std::map<char, int> mapCounts;
int iLen = strInput.size();
for(int i = 0; i < iLen; ++i) {
if(mapCounts.find(strInput[i]) == mapCounts.end())
mapCounts[strInput[i]] = 1;
else
++mapCounts[strInput[i]] ;;
}
for(auto it = mapCounts.begin(); it != mapCounts.end(); ++it) {
std::cout << it->first << ':' << it->second << std::endl;
}
return 0;
}

### 1022. D进制的A+B (20)

#include <iostream>
#include <string>
#include <algorithm>

{
if(0 == iNum) return "0";
std::string strResult("");
while(iNum) {
}
std::reverse(strResult.begin(), strResult.end());
return strResult;
}

int main()
{
int A, B, D;
std::cin >> A >> B >> D;
if(10 == D) {
std::cout << A + B << std::endl;
return 0;
}
std::cout << gao(A + B, D) << std::endl;
return 0;
}

### 1023. 组个最小数 (20)

#include <iostream>
const int N = 10;

void gao(int cnt[N]) {
if(0 == cnt[0]) {
for(int i = 1; i < N; ++i) {
while(cnt[i]--) std::cout << i;
}
return ;
}
int idxFirstNonZeroAfterZero = 0;
while(!cnt[++idxFirstNonZeroAfterZero]) ;
std::cout << idxFirstNonZeroAfterZero;
--cnt[idxFirstNonZeroAfterZero];
for(int i = 0; i < N; ++i) {
while(cnt[i]--) std::cout << i;
}
return ;
}

int main()
{
int iCounts[N];
for(int i = 0; i < N; ++i)
std::cin >> iCounts[i];
gao(iCounts);
return 0;
}

### 1025. 反转链表 (25)

Written on March 7, 2014