标签:
A.水题 数字翻转,将每一位大于等于5的数字t翻转成9-t,注意不要有前导0,且翻转后数字的位数不变(即9999->9000...刚开始以为应该翻转成0了= =)
1 #include<iostream> 2 #include<cstdio> 3 #include<cstdlib> 4 #include<cstring> 5 using namespace std; 6 int main() 7 { 8 char x[20]; 9 cin >> x; 10 int len = strlen(x); 11 for(int i = 0; i < len; i++) 12 if(x[i] >= ‘5‘) x[i] = ‘9‘ - x[i] + ‘0‘; 13 if(x[0] == ‘0‘) x[0] = ‘9‘; 14 cout << x << endl; 15 return 0; 16 } 17 #include<iostream> 18 #include<cstdio> 19 #include<cstdlib> 20 #include<cstring> 21 using namespace std; 22 int main() 23 { 24 char x[20]; 25 cin >> x; 26 int len = strlen(x); 27 for(int i = 0; i < len; i++) 28 if(x[i] >= ‘5‘) x[i] = ‘9‘ - x[i] + ‘0‘; 29 if(x[0] == ‘0‘) x[0] = ‘9‘; 30 cout << x << endl; 31 return 0; 32 }
B.水题 斜率,每输入一个坐标(xi,yi)求出该点与标准点连线的斜率并记入数组k[]中,排序(sort),去重(unique);
NOTE:斜率注意的基本问题---斜率为无穷大与0时的特判;
1 #include<iostream> 2 #include<cstdio> 3 #include<cstdlib> 4 #include<cstring> 5 #include<algorithm> 6 using namespace std; 7 const int maxn = 1010; 8 int main() 9 { 10 int n, cnt1 = 0, cnt2 = 0; 11 double x0, y0, x, y; 12 double k[maxn]; 13 scanf("%d%lf%lf", &n, &x0, &y0); 14 for(int i = 0; i < n; i++) 15 { 16 scanf("%lf%lf", &x, &y); 17 if(x-x0 == 0) {cnt1++; k[i] = 0; continue;} 18 if(y-y0 == 0) {cnt2++; k[i] = 0; continue;} 19 k[i] = (y-y0)/(x-x0); 20 } 21 sort(k, k+n); 22 int ans = unique(k, k+n) - k; 23 if(cnt1 && cnt2) ans++; 24 cout << ans << endl; 25 return 0; 26 }
标签:
原文地址:http://www.cnblogs.com/LLGemini/p/4293185.html