68962

简单题

字符串处理

1001 A+B Format (20 分)  

Calculate a+b and output the sum in standard format -- that is, the digits must be separated into groups of three by commas (unless there are less than four digits).

<h3 id="input-specification-">Input Specification:</h3>

Each input file contains one test case. Each case contains a pair of integers a and b where −. The numbers are separated by a space.

<h3 id="output-specification-">Output Specification:</h3>

For each test case, you should output the sum of a and b in one line. The sum must be written in the standard format.

<h3 id="sample-input-">Sample Input:</h3> -1000000 9 <h3 id="sample-output-">Sample Output:</h3> -999,991 #include <iostream> #include <algorithm> using namespace std; int main() { int a,b; cin>>a>>b; int c=a+b; int s[100],ans[100]; bool flag=false; if(c<0) flag=true; c=abs(c); if(c==0) { cout<<0; return 0; } int k=0,temp,count=0,j=0; while(c!=0) { s[k++]=c%10; c/=10; } for(int i=0;i<k;i++) { count++; ans[j++]=s[i]; if(count%3==0&&i<k-1) ans[j++]=-1; } if(flag) printf("-"); for(int i=j-1;i>=0;i--) { if(ans[i]==-1) cout<<',';else cout<<ans[i]; } return 0; }

想法很简单,细节注意,手生了,花时间有点多

1005 Spell It Right (20 分)  

Given a non-negative integer N, your task is to compute the sum of all the digits of N, and output every digit of the sum in English.

<h3 id="input-specification-">Input Specification:</h3>

Each input file contains one test case. Each case occupies one line which contains an N (≤).

<h3 id="output-specification-">Output Specification:</h3>

For each test case, output in one line the digits of the sum in English words. There must be one space between two consecutive words, but no extra space at the end of a line.

<h3 id="sample-input-">Sample Input:</h3> 12345 <h3 id="sample-output-">Sample Output:</h3> one five #include <iostream> #include <string> using namespace std; string num[10]={"zero","one","two","three","four","five","six","seven","eight","nine"}; string str; int ans[1000]; int main() { cin>>str; int sum=0; for(int i=0;i<str.size();i++) { sum+=str[i]-'0'; } int j=0; while(sum!=0) { ans[j++]=sum%10; sum/=10; } for(int i=j-1;i>0;i--) cout<<num[ans[i]]<<" "; cout<<num[ans[0]]; return 0; } 1035 Password (20 分)  

To prepare for PAT, the judge sometimes has to generate random passwords for the users. The problem is that there are always some confusing passwords since it is hard to distinguish 1 (one) from l (L in lowercase), or 0 (zero) from O (o in uppercase). One solution is to replace 1 (one) by @0 (zero) by %l by L, and Oby o. Now it is your job to write a program to check the accounts generated by the judge, and to help the juge modify the confusing passwords.

<h3 id="input-specification-">Input Specification:</h3>

Each input file contains one test case. Each case contains a positive integer N (≤), followed by N lines of accounts. Each account consists of a user name and a password, both are strings of no more than 10 characters with no space.

<h3 id="output-specification-">Output Specification:</h3>

For each test case, first print the number M of accounts that have been modified, then print in the following Mlines the modified accounts info, that is, the user names and the corresponding modified passwords. The accounts must be printed in the same order as they are read in. If no account is modified, print in one line There are N accounts and no account is modified where N is the total number of accounts. However, if N is one, you must print There is 1 account and no account is modified instead.

#include <iostream> #include <string> #include <algorithm> using namespace std; struct inf { string name; string pw; bool f; }all[1010]; int sum=0; void mod(inf &a) { bool flag=true; for(int i=0;i<a.pw.size();i++) { switch (a.pw[i]) { case '1': a.pw[i]='@';flag=false;break; case '0': a.pw[i]='%';flag=false;break; case 'l': a.pw[i]='L';flag=false;break; case 'O': a.pw[i]='o';flag=false;break; } } if(flag==false) { a.f=true; sum++; } } int main() { int n; cin>>n; for(int i=0;i<n;i++) { cin>>all[i].name>>all[i].pw; all[i].f=false; mod(all[i]); } if(sum==0) { if(n==1) cout<<"There is "<<n<<" account and no account is modified"<<endl; else cout<<"There are "<<n<<" accounts and no account is modified"<<endl; } else { cout<<sum<<endl; for(int i=0;i<n;i++) { if(all[i].f) { cout<<all[i].name<<' '<<all[i].pw<<endl; } } } return 0; } 1082 Read Number in Chinese (25 分)  

Given an integer with no more than 9 digits, you are supposed to read it in the traditional Chinese way. Output Fu first if it is negative. For example, -123456789 is read as Fu yi Yi er Qian san Bai si Shi wu Wan liu Qian qi Bai ba Shi jiu. Note: zero (ling) must be handled correctly according to the Chinese tradition. For example, 100800 is yi Shi Wan ling ba Bai.

<h3 id="input-specification-">Input Specification:</h3>

Each input file contains one test case, which gives an integer with no more than 9 digits.

<h3 id="output-specification-">Output Specification:</h3>

For each test case, print in a line the Chinese way of reading the number. The characters are separated by a space and there must be no extra space at the end of the line.

<h3 id="sample-input-1-">Sample Input 1:</h3> -123456789 <h3 id="sample-output-1-">Sample Output 1:</h3> Fu yi Yi er Qian san Bai si Shi wu Wan liu Qian qi Bai ba Shi jiu <h3 id="sample-input-2-">Sample Input 2:</h3> 100800 <h3 id="sample-output-2-">Sample Output 2:</h3> yi Shi Wan ling ba Bai #include <cstdio> #include <cstring> using namespace std; char num[10][5]={"ling","yi","er","san","si","wu","liu","qi","ba","jiu"}; char wei[5][5]={"Shi","Bai","Qian","Wan","Yi"}; int main() { char str[15]; scanf("%s",str); int len=strlen(str); int left=0,right=len-1; if(str[0]=='-') { printf("Fu");left++; } while(left+4<=right) right-=4; while(left<len) { bool flag=false; bool isprint=false; while(left<=right) { if(left>0&&str[left]=='0') { flag=true; }else { if(flag==true) { printf(" ling"); flag=false; } if(left>0) printf(" "); printf("%s",num[str[left]-'0']); isprint=true; if(left!=right) printf(" %s",wei[right-left-1]); } left++; } if(isprint==true&&right!=len-1) printf(" %s",wei[(len-1-right)/4 +2]); right+=4; } return 0; }

直接一位一位处理,却在处理0的间隔和末位时错了,本来我想通过复杂的逻辑把所有的特殊情况都能包含,然而要么是我太菜要么是这个方法本身就有Question。钻牛角尖好久还是只能得一半分,

不得不直接学习参考答案了,时间不多了。 

查找

1006 Sign In and Sign Out (25 分)  

At the beginning of every day, the first person who signs in the computer room will unlock the door, and the last one who signs out will lock the door. Given the records of signing in's and out's, you are supposed to find the ones who have unlocked and locked the door on that day.

<h3 id="input-specification-">Input Specification:</h3>

Each input file contains one test case. Each case contains the records for one day. The case starts with a positive integer M, which is the total number of records, followed by M lines, each in the format:

ID_number Sign_in_time Sign_out_time

where times are given in the format HH:MM:SS, and ID_number is a string with no more than 15 characters.

<h3 id="output-specification-">Output Specification:</h3>

For each test case, output in one line the ID numbers of the persons who have unlocked and locked the door on that day. The two ID numbers must be separated by one space.

Note: It is guaranteed that the records are consistent. That is, the sign in time must be earlier than the sign out time for each person, and there are no two persons sign in or out at the same moment.

<h3 id="sample-input-">Sample Input:</h3> 3 CS301111 15:30:28 17:00:10 SC3021234 08:00:00 11:25:25 CS301133 21:45:00 21:58:40 <h3 id="sample-output-">Sample Output:</h3> SC3021234 CS301133 #include <iostream> #include <cstdio> #include <string> using namespace std; struct record { string id; int in; int out; }all[10000]; int main() { int m,hour,min,sec; cin>>m; int first,minin=240000,last,maxout=0; for(int i=0;i<m;i++) { cin>>all[i].id; scanf("%d:%d:%d",&hour,&min,&sec); all[i].in=hour*10000+min*100+sec; if(all[i].in<minin) { minin=all[i].in;first=i; } scanf("%d:%d:%d",&hour,&min,&sec); all[i].out=hour*10000+min*100+sec; if(all[i].out>maxout) { maxout=all[i].out;last=i; } } cout<<all[first].id<<' '<<all[last].id; return 0; } 1011 World Cup Betting (20 分)  

With the 2010 FIFA World Cup running, football fans the world over were becoming increasingly excited as the best players from the best teams doing battles for the World Cup trophy in South Africa. Similarly, football betting fans were putting their money where their mouths were, by laying all manner of World Cup bets.

Chinese Football Lottery provided a "Triple Winning" game. The rule of winning was simple: first select any three of the games. Then for each selected game, bet on one of the three possible results -- namely W for win, T for tie, and L for lose. There was an odd assigned to each result. The winner's odd would be the product of the three odds times 65%.

For example, 3 games' odds are given as the following:

W T L 1.1 2.5 1.7 1.2 3.1 1.6 4.1 1.2 1.1

To obtain the maximum profit, one must buy W for the 3rd game, T for the 2nd game, and T for the 1st game. If each bet takes 2 yuans, then the maximum profit would be ( yuans (accurate up to 2 decimal places).

<h3 id="input-specification-">Input Specification:</h3>

Each input file contains one test case. Each case contains the betting information of 3 games. Each game occupies a line with three distinct odds corresponding to WT and L.

<h3 id="output-specification-">Output Specification:</h3>

For each test case, print in one line the best bet of each game, and the maximum profit accurate up to 2 decimal places. The characters and the number must be separated by one space.

<h3 id="sample-input-">Sample Input:</h3> 1.1 2.5 1.7 1.2 3.1 1.6 4.1 1.2 1.1 <h3 id="sample-output-">Sample Output:</h3> T T W 39.31 #include <cstdio> using namespace std; char c[3]={'W','T','L'}; int main() { double temp,maxt,sum=1; int index[3]; for(int i=0;i<3;i++) { maxt=0; for(int j=0;j<3;j++) { scanf("%lf",&temp); if(temp>maxt) { index[i]=j;maxt=temp; } } sum*=maxt; } for(int i=0;i<3;i++) printf("%c ",c[index[i]]); sum=(sum*0.65-1)*2; printf("%.2f",sum); return 0; } 1036 Boys vs Girls (25 分)  

This time you are asked to tell the difference between the lowest grade of all the male students and the highest grade of all the female students.

<h3 id="input-specification-">Input Specification:</h3>

Each input file contains one test case. Each case contains a positive integer N, followed by N lines of student information. Each line contains a student's namegenderID and grade, separated by a space, where nameand ID are strings of no more than 10 characters with no space, gender is either F (female) or M (male), and grade is an integer between 0 and 100. It is guaranteed that all the grades are distinct.

<h3 id="output-specification-">Output Specification:</h3>

For each test case, output in 3 lines. The first line gives the name and ID of the female student with the highest grade, and the second line gives that of the male student with the lowest grade. The third line gives the difference grade​F​​−grade​M​​. If one such kind of student is missing, output Absent in the corresponding line, and output NA in the third line instead.

<h3 id="sample-input-1-">Sample Input 1:</h3> 3 Joe M Math990112 89 Mike M CS991301 100 Mary F EE990830 95 <h3 id="sample-output-1-">Sample Output 1:</h3> Mary EE990830 Joe Math990112 6 #include <iostream> #include <string> #include <algorithm> using namespace std; struct inf { string name; char gender; string id; int grade; }all[1010]; bool cmp(inf a,inf b) { if(a.gender!=b.gender) return a.gender<b.gender; else return a.grade>b.grade; } int main() { int n; cin>>n; for(int i=0;i<n;i++) { cin>>all[i].name>>all[i].gender>>all[i].id>>all[i].grade; } sort(all,all+n,cmp); bool flag1=false,flag2=false; if(all[0].gender=='F') { cout<<all[0].name<<' '<<all[0].id<<endl; flag1=true; }else cout<<"Absent"<<endl; if(all[n-1].gender=='M') { cout<<all[n-1].name<<' '<<all[n-1].id<<endl; flag2=true; }else cout<<"Absent"<<endl; if(flag1&&flag2) cout<<abs(all[0].grade-all[n-1].grade); else cout<<"NA"; return 0; }

简单模拟

1002 A+B for Polynomials (25 分)

This time, you are supposed to find A+B where A and B are two polynomials.

<h3 id="input-specification-">Input Specification:</h3>

Each input file contains one test case. Each case occupies 2 lines, and each line contains the information of a polynomial:

K N​1​​ a​N​1​​​​ N​2​​ a​N​2​​​​ ... N​K​​ a​N​K​​​​

where K is the number of nonzero terms in the polynomial, N​i​​ and a​N​i​​​​ (,) are the exponents and coefficients, respectively. It is given that 1,0.

<h3 id="output-specification-">Output Specification:</h3>

For each test case you should output the sum of A and B in one line, with the same format as the input. Notice that there must be NO extra space at the end of each line. Please be accurate to 1 decimal place.

<h3 id="sample-input-">Sample Input:</h3> 2 1 2.4 0 3.2 2 2 1.5 1 0.5 <h3 id="sample-output-">Sample Output:</h3> 3 2 1.5 1 2.9 0 3.2 #include <cstdio> using namespace std; double ans[1011]={}; int main() { int n,k,maxn=0; double a; scanf("%d",&k); for(int i=0;i<k;i++) { scanf("%d%lf",&n,&a); ans[n]+=a; if(n>maxn) maxn=n; } scanf("%d",&k); for(int i=0;i<k;i++) { scanf("%d%lf",&n,&a); ans[n]+=a; if(n>maxn) maxn=n; } int num=0; for(int i=0;i<=maxn;i++) { if(ans[i]!=0) num++; } printf("%d",num); for(int i=maxn;i>=0;i--) { if(ans[i]!=0) printf(" %d %.1f",i,ans[i]); } return 0; }

刚开始用map做出现了未知错误,本来应是送分题,不过这是早年的了,现在应该不会出这样简单的。

1009 Product of Polynomials (25 分)  

This time, you are supposed to find A×B where A and B are two polynomials.

<h3 id="input-specification-">Input Specification:</h3>

Each input file contains one test case. Each case occupies 2 lines, and each line contains the information of a polynomial:

K N​1​​ a​N​1​​​​ N​2​​ a​N​2​​​​ ... N​K​​ a​N​K​​​​

where K is the number of nonzero terms in the polynomial, N​i​​ and a​N​i​​​​ (,) are the exponents and coefficients, respectively. It is given that 1, 0.

<h3 id="output-specification-">Output Specification:</h3>

For each test case you should output the product of A and B in one line, with the same format as the input. Notice that there must be NO extra space at the end of each line. Please be accurate up to 1 decimal place.

<h3 id="sample-input-">Sample Input:</h3> 2 1 2.4 0 3.2 2 2 1.5 1 0.5 <h3 id="sample-output-">Sample Output:</h3> 3 3 3.6 2 6.0 1 1.6 #include <cstdio> using namespace std; struct poly { int n; double a; }p[1005]; double ans[2010]; int main() { int k,n; double a; scanf("%d",&k); for(int i=0;i<k;i++) { scanf("%d %lf",&p[i].n,&p[i].a); } int s; scanf("%d",&s); for(int i=0;i<s;i++) { scanf("%d %lf",&n,&a); for(int j=0;j<k;j++) { ans[n+p[j].n]+=a*p[j].a; } } int sum=0; for(int i=0;i<=2000;i++) { if(ans[i]!=0.0) sum++; } printf("%d",sum); for(int i=2000;i>=0;i--) { if(ans[i]!=0.0) printf(" %d %.1f",i,ans[i]); } return 0; }

多项式乘法,按正常计算时的方法模拟,一般不需要多想。

1042 Shuffling Machine (20 分)  

Shuffling is a procedure used to randomize a deck of playing cards. Because standard shuffling techniques are seen as weak, and in order to avoid "inside jobs" where employees collaborate with gamblers by performing inadequate shuffles, many casinos employ automatic shuffling machines. Your task is to simulate a shuffling machine.

The machine shuffles a deck of 54 cards according to a given random order and repeats for a given number of times. It is assumed that the initial status of a card deck is in the following order:

S1, S2, ..., S13, H1, H2, ..., H13, C1, C2, ..., C13, D1, D2, ..., D13, J1, J2

where "S" stands for "Spade", "H" for "Heart", "C" for "Club", "D" for "Diamond", and "J" for "Joker". A given order is a permutation of distinct integers in [1, 54]. If the number at the i-th position is j, it means to move the card from position i to position j. For example, suppose we only have 5 cards: S3, H5, C1, D13 and J2. Given a shuffling order {4, 2, 5, 3, 1}, the result will be: J2, H5, D13, S3, C1. If we are to repeat the shuffling again, the result will be: C1, H5, S3, J2, D13.

<h3 id="input-specification-">Input Specification:</h3>

Each input file contains one test case. For each case, the first line contains a positive integer K (≤) which is the number of repeat times. Then the next line contains the given order. All the numbers in a line are separated by a space.

<h3 id="output-specification-">Output Specification:</h3>

For each test case, print the shuffling results in one line. All the cards are separated by a space, and there must be no extra space at the end of the line.

<h3 id="sample-input-">Sample Input:</h3> 2 36 52 37 38 3 39 40 53 54 41 11 12 13 42 43 44 2 4 23 24 25 26 27 6 7 8 48 49 50 51 9 10 14 15 16 5 17 18 19 1 20 21 22 28 29 30 31 32 33 34 35 45 46 47 <h3 id="sample-output-">Sample Output:</h3> S7 C11 C10 C12 S1 H7 H8 H9 D8 D9 S11 S12 S13 D10 D11 D12 S3 S4 S6 S10 H1 H2 C13 D2 D3 D4 H6 H3 D13 J1 J2 C1 C2 C3 C4 D1 S5 H5 H11 H12 C6 C7 C8 C9 S2 S8 S9 H10 D5 D6 D7 H4 H13 C5 #include <cstdio> #include <cstring> #include <algorithm> using namespace std; int mov[54]; char init[54][4]={ "S1","S2","S3","S4","S5","S6","S7","S8","S9","S10","S11","S12","S13", "H1","H2","H3","H4","H5","H6","H7","H8","H9","H10","H11","H12","H13", "C1","C2","C3","C4","C5","C6","C7","C8","C9","C10","C11","C12","C13", "D1","D2","D3","D4","D5","D6","D7","D8","D9","D10","D11","D12","D13", "J1","J2"}; char mid[54][4]; void tra() { for(int i=0;i<54;i++) { strcpy(mid[mov[i]],init[i]); } for(int i=0;i<54;i++) { strcpy(init[i],mid[i]); } } int main() { int n,temp; scanf("%d",&n); for(int i=0;i<54;i++) { scanf("%d",&temp); mov[i]=temp-1; } while(n--) tra(); for(int i=0;i<54;i++) { printf("%s",init[i]); if(i<53) printf(" "); } return 0; } 1031 Hello World for U (20 分)  

Given any string of N (≥) characters, you are asked to form the characters into the shape of U. For example, helloworld can be printed as:

h d e l l r lowo

That is, the characters must be printed in the original order, starting top-down from the left vertical line with n​1​​characters, then left to right along the bottom line with n​2​​ characters, and finally bottom-up along the vertical line with n​3​​ characters. And more, we would like U to be as squared as possible -- that is, it must be satisfied that n​1​​=n​3​​=max { k | k≤n​2​​ for all 3 } with n​1​​+n​2​​+n​3​​−2=N.

<h3 id="input-specification-">Input Specification:</h3>

Each input file contains one test case. Each case contains one string with no less than 5 and no more than 80 characters in a line. The string contains no white space.

<h3 id="output-specification-">Output Specification:</h3>

For each test case, print the input string in the shape of U as specified in the description.

<h3 id="sample-input-">Sample Input:</h3> helloworld! <h3 id="sample-output-">Sample Output:</h3> h ! e d l l lowor #include <cstdio> #include <cstring> #include <algorithm> using namespace std; char init[82]; int main() { scanf("%s",init); int l=strlen(init); int n1,n2,n3; for(n2=3;n2<l;n2++) { if((l-n2+2)%2==0) { n1=n3=(l-n2+2)/2; if(n1<=n2) break; } } char ans[n1][n2]; fill(ans[0],ans[0]+n1*n2,' '); int k=0; for(int i=0;i<n1;i++) ans[i][0]=init[k++]; for(int i=1;i<n2;i++) ans[n1-1][i]=init[k++]; for(int i=n3-2;i>=0;i--) ans[i][n2-1]=init[k++]; for(int i=0;i<n1;i++) { for(int j=0;j<n2;j++) { printf("%c",ans[i][j]); } printf("\n"); } return 0; } 1046 Shortest Distance (20 分)  

The task is really simple: given N exits on a highway which forms a simple cycle, you are supposed to tell the shortest distance between any pair of exits.

<h3 id="input-specification-">Input Specification:</h3>

Each input file contains one test case. For each case, the first line contains an integer N (in [3]), followed by N integer distances D​1​​ D​2​​ ⋯ D​N​​, where D​i​​ is the distance between the i-th and the (-st exits, and D​N​​ is between the N-th and the 1st exits. All the numbers in a line are separated by a space. The second line gives a positive integer M (≤), with M lines follow, each contains a pair of exit numbers, provided that the exits are numbered from 1 to N. It is guaranteed that the total round trip distance is no more than 1.

<h3 id="output-specification-">Output Specification:</h3>

For each test case, print your results in M lines, each contains the shortest distance between the corresponding given pair of exits.

#include <iostream> #include <algorithm> using namespace std; int n,m,len=0; int l[100010],dis[100010]; int main() { cin>>n; int x,y,t; for(int i=1;i<=n;i++) { cin>>l[i]; len+=l[i]; dis[i]=len; } cin>>m; for(int i=0;i<m;i++) { cin>>x>>y; if(x>y) { t=y;y=x;x=t; } int ans=dis[y-1]-dis[x-1]; cout<<min(ans,len-ans)<<endl; } return 0; }

虽然很简单就能得17分,但为了解决超时,还是有些方法需要注意。和图算法里的思想一样,开一个数组存下从第一个点到当前点的权值之和(和最短路径算法中从源点出发到各点的路程)

初始化时就处理好,直接查询即可。

 进制

1019 General Palindromic Number (20 分)  

A number that will be the same when it is written forwards or backwards is known as a Palindromic Number. For example, 1234321 is a palindromic number. All single digit numbers are palindromic numbers.

Although palindromic numbers are most often considered in the decimal system, the concept of palindromicity can be applied to the natural numbers in any numeral system. Consider a number N>0 in base b≥2, where it is written in standard notation with k+1 digits a​i​​ as (. Here, as usual, 0 for all i and a​k​​ is non-zero. Then N is palindromic if and only if a​i​​=a​k−i​​ for all i. Zero is written 0 in any base and is also palindromic by definition.

Given any positive decimal integer N and a base b, you are supposed to tell if N is a palindromic number in base b.

<h3 id="input-specification-">Input Specification:</h3>

Each input file contains one test case. Each case consists of two positive numbers N and b, where 0 is the decimal number and 2 is the base. The numbers are separated by a space.

<h3 id="output-specification-">Output Specification:</h3>

For each test case, first print in one line Yes if N is a palindromic number in base b, or No if not. Then in the next line, print N as the number in base b in the form "a​k​​ a​k−1​​ ... a​0​​". Notice that there must be no extra space at the end of output.

<h3 id="sample-input-1-">Sample Input 1:</h3> 27 2 <h3 id="sample-output-1-">Sample Output 1:</h3> Yes 1 1 0 1 1 <h3 id="sample-input-2-">Sample Input 2:</h3> 121 5 <h3 id="sample-output-2-">Sample Output 2:</h3> No 4 4 1 #include <cstdio> #include <vector> using namespace std; int main() { int n,b; vector<int> ans; scanf("%d %d",&n,&b); while(n!=0) { ans.push_back(n%b); n/=b; } bool flag=true; for(int i=0;i<ans.size()/2;i++) { if(ans[i]!=ans[ans.size()-1-i]) { flag=false;break; } } if(flag) printf("Yes\n"); else printf("No\n"); for(int i=ans.size()-1;i>0;i--) printf("%d ",ans[i]); printf("%d",ans[0]); return 0; } 1027 Colors in Mars (20 分)  

People in Mars represent the colors in their computers in a similar way as the Earth people. That is, a color is represented by a 6-digit number, where the first 2 digits are for Red, the middle 2 digits for Green, and the last 2 digits for Blue. The only difference is that they use radix 13 (0-9 and A-C) instead of 16. Now given a color in three decimal numbers (each between 0 and 168), you are supposed to output their Mars RGB values.

<h3 id="input-specification-">Input Specification:</h3>

Each input file contains one test case which occupies a line containing the three decimal color values.

<h3 id="output-specification-">Output Specification:</h3>

For each test case you should output the Mars RGB value in the following format: first output #, then followed by a 6-digit number where all the English characters must be upper-cased. If a single color is only 1-digit long, you must print a 0 to its left.

<h3 id="sample-input-">Sample Input:</h3> 15 43 71 <h3 id="sample-output-">Sample Output:</h3> #123456 #include <iostream> #include <string> using namespace std; char mar[13]={'0','1','2','3','4','5','6','7','8','9','A','B','C'}; string tra(int k) { string s=""; while(k!=0) { s=mar[k%13]+s; k/=13; } while(s.size()<2) { s="0"+s; } return s; } int main() { int r,g,b; cin>>r>>g>>b; string ans="#"; ans+=tra(r)+tra(g)+tra(b); cout<<ans; return 0; }

来源:博客园

作者:FremontUltimate

链接:https://www.cnblogs.com/fremontxutheultimate/p/11379960.html

Recommend