Link: http://pat.zju.edu.cn/contests/pat-b-practise/1006
Let's use the letter B to represent "Hundred", the letter S to represent "Ten", and "12... N (<10) is a single digit. In another format, a positive integer of no more than three digits is output. For example, 234 should be output as bbsss1234 because it has two "hundreds", three "Ten", and four digits.
Input Format:Each test input contains one test case and a positive integer N (<1000 ).
Output Format:The output of each test case occupies one line and outputs N in the specified format.
Input Example 1:
234
Output Example 1:
BBSSS1234
Input Example 2:
23
Output Example 2:
SS123
The Code is as follows:
#include <cstdio>#include <cstring>char s[4];void solve(char s[]){ int len = strlen(s); for(int i = 0; i < len; i++) { if(len == 3 && i == 0) { for(int j = 0; j < s[i]-'0'; j++) { printf("B"); } } else if(len == 3 && i == 1) { for(int j = 0; j < s[i]-'0'; j++) { printf("S"); } } else if(len == 2 && i == 0) { for(int j = 0; j < s[i]-'0'; j++) { printf("S"); } } else { for(int j = 1; j <= s[i]-'0'; j++) { printf("%d",j); } } }}int main(){ while(~scanf("%s",s)) { solve(s); printf("\n"); } return 0;}
1006. Output an integer (15) in another format (zjupat)