CF305A
本来是简单题,不过就是题意难理解一点。。。
对于两个数能相加 要保证每一位上相应位置上至少有一个0。
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 /* 2 水题不水 3 */ 4 #include<stdio.h> 5 #include<string.h> 6 #include<stdlib.h> 7 #include<algorithm> 8 #include<iostream> 9 #include<queue> 10 #include<map> 11 #include<math.h> 12 using namespace std; 13 typedef long long ll; 14 //typedef __int64 int64; 15 const int maxn = 105; 16 const int inf = 0x7fffffff; 17 const double pi=acos(-1.0); 18 const double eps = 1e-8; 19 20 int a[ maxn ]; 21 22 int main(){ 23 int n; 24 while( scanf("%d",&n)==1 ){ 25 for( int i=0;i<n;i++ ){ 26 scanf("%d",&a[i]); 27 } 28 int f1,f2,f3,f4; 29 int add = -1; 30 f1 = f2 = f3 = f4 = -1; 31 int sum = 0; 32 for( int i=0;i<n;i++ ){ 33 if( a[i]==0&&f1==-1 ){ 34 f1 = 0; 35 sum++; 36 } 37 else if( a[i]==100&&f2==-1 ){ 38 f2 = 100; 39 sum++; 40 } 41 else if( f3==-1&&a[i]>=10&&a[i]<=90&&a[i]%10==0 ){ 42 f3 = a[i]; 43 sum++; 44 } 45 else if( f4==-1&&a[i]>0&&a[i]<=9 ){ 46 f4 = a[i]; 47 sum++; 48 } 49 else if( a[i]>=10&&a[i]<=99&&a[i]%10!=0&&add==-1 ) add = a[i]; 50 } 51 //printf("sum=%d\nadd=%d\n",sum,add); 52 if( sum==4 ){ 53 printf("4\n"); 54 printf("%d %d %d %d\n",f1,f2,f3,f4); 55 continue; 56 } 57 if( f1==-1&&f2==-1&&f3==-1&&f4==-1 ){ 58 printf("1\n%d\n",a[0]); 59 continue; 60 } 61 if( sum==3 ){ 62 printf("3\n"); 63 int cc = 0; 64 if( f1!=-1) { 65 if( cc==0 ) { 66 printf("%d",f1); 67 cc++; 68 } 69 else printf(" %d\n",f1); 70 } 71 if( f2!=-1) { 72 if( cc==0 ) { 73 printf("%d",f2); 74 cc++; 75 } 76 else printf(" %d\n",f2); 77 } 78 if( f3!=-1) { 79 if( cc==0 ) { 80 printf("%d",f3); 81 cc++; 82 } 83 else printf(" %d\n",f3); 84 } 85 if( f4!=-1) { 86 if( cc==0 ) { 87 printf("%d",f4); 88 cc++; 89 } 90 else printf(" %d\n",f4); 91 } 92 continue; 93 } 94 if( sum==2 ){ 95 if( f1!=-1&&f2!=-1 ){ 96 if( add!=-1 ){ 97 printf("3\n"); 98 printf("%d %d %d\n",f1,f2,add); 99 } 100 else { 101 printf("2\n"); 102 printf("%d %d\n",f1,f2); 103 } 104 continue; 105 } 106 printf("2\n"); 107 int cc = 0; 108 if( f1!=-1) { 109 if( cc==0 ) { 110 printf("%d",f1); 111 cc++; 112 } 113 else printf(" %d\n",f1); 114 } 115 if( f2!=-1) { 116 if( cc==0 ) { 117 printf("%d",f2); 118 cc++; 119 } 120 else printf(" %d\n",f2); 121 } 122 if( f3!=-1) { 123 if( cc==0 ) { 124 printf("%d",f3); 125 cc++; 126 } 127 else printf(" %d\n",f3); 128 } 129 if( f4!=-1) { 130 if( cc==0 ) { 131 printf("%d",f4); 132 cc++; 133 } 134 else printf(" %d\n",f4); 135 } 136 continue; 137 } 138 if( sum==1 ){ 139 if( f1!=-1 ){ 140 if( add!=-1 ){ 141 printf("2\n"); 142 printf("%d %d\n",add,f1); 143 } 144 else printf("1\n%d\n",f1); 145 continue; 146 } 147 if( f2!=-1 ){ 148 if( add!=-1 ){ 149 printf("2\n"); 150 printf("%d %d\n",add,f2); 151 } 152 else printf("1\n%d\n",f2); 153 continue; 154 } 155 printf("1\n"); 156 if( f1!=-1 ) printf("%d\n",f1); 157 if( f2!=-1 ) printf("%d\n",f2); 158 if( f3!=-1 ) printf("%d\n",f3); 159 if( f4!=-1 ) printf("%d\n",f4); 160 continue; 161 } 162 } 163 return 0; 164 }
keep moving...