1 条题解
-
0
C :
#include <stdio.h> #include <math.h> #include <string.h> int main() { int t = 0; scanf("%d", &t); getchar(); while(t--) { char s[100] = {0}; gets(s); int one = 0; int two = 0; int three = 0; for(int i = 0; i <(int)strlen(s); i ++) { if(s[i] == '1') one ++; if(s[i] == '2') two ++; if(s[i] == '3') three ++; } char ss[100] = {0}; for(int x = 0; x < one; x++) strcat(ss, "1+"); for(int y = 0; y < two; y++) strcat(ss, "2+"); for(int z = 0; z < three; z++) strcat(ss, "3+"); ss[(int)strlen(s)] = 0; printf("%s\n", ss); } return 0; }
C++ :
#include <iostream> #include <string> #include <cstring> #include <fstream> #include <algorithm> using namespace std; int saver[200]; int main() { int testcase; // ifstream cin; // ofstream cout; // cin.open("j.in"); // cout.open("j.out"); cin>>testcase; while(testcase--) { string tar,tmp; int count1=0,count2=0,count3=0; cin>>tar; memset(saver,0,sizeof(saver)); for(int i=0;i<tar.length();i++) { if(tar[i]=='1') count1++; if(tar[i]=='2') count2++; if(tar[i]=='3') count3++; } int p=count1+count2+count3-1; int q=0; for(int i=0;i<count1;i++) { cout<<1; if(q!=p) { cout<<"+"; q++; } } for(int j=0;j<count2;j++) { cout<<2; if(q!=p) { cout<<"+"; q++; } } for(int k=0;k<count3;k++) { cout<<3; if(q!=p) { cout<<"+"; q++; } } cout<<endl; } return 0; }
Pascal :
var n,i,s1,s2,s3,s4:longint; s:string; begin readln(n); for i:=1 to n do begin s1:=0; s2:=0; s3:=0; readln(s); case s[1] of '1':inc(s1); '2':inc(s2); '3':inc(s3); end; s4:=pos('+',s); while s4<>0 do begin case s[s4+1] of '1':inc(s1); '2':inc(s2); '3':inc(s3); end; delete(s,s4,2); s4:=pos('+',s); end; while s1<>0 do begin if (s1=1) and (s2=0) and (s3=0) then write('1') else write('1+'); dec(s1); end; while s2<>0 do begin if (s2=1) and (s3=0) then write('2') else write('2+'); dec(s2); end; while s3<>0 do begin if s3=1 then write('3') else write('3+'); dec(s3); end; writeln; end; end.
- 1
信息
- ID
- 3377
- 时间
- 2000ms
- 内存
- 256MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者