- 1、字母图形
- 2、01字串
- 3、Fibonacci数列
- 4、圆的面积
- 5、十六进制转八进制
- 6、十六进制转十进制
- 7、十进制转十六进制
//a ber #include2、01字串using namespace std; int n, m; char a[100][100]; signed main() { scanf("%d%d", &n, &m); //打印第一行 for(int i = 0; i < m; i++) { a[0][i] = i + 'A'; } for(int i = 1; i <= n; i++) { for(int j = 0; j < m; j++) { //规律 i > j ? a[i][j] = char(a[i - 1][j] + 1) : a[i][j] = char(a[i - 1][j] - 1); } } for(int i = 0; i < n; i++) { puts(a[i]); } return 0; }
//a ber //水题 当成二进制数做就行了 0-31 #include3、Fibonacci数列using namespace std; int a[5]; void print(int x) { memset(a, 0, sizeof a); int cnt = 0; while(x) { int c = x % 2; a[cnt++] = c; x /= 2; } a[cnt++] = x; for(int i = 4; i >= 0; i--) printf("%d", a[i]); } signed main() { for(int i = 0; i < 32; i++) { print(i); puts(""); } return 0; }
//a ber #include4、圆的面积using namespace std; const int N = 1e6 + 7; int n, f[N]; signed main() { scanf("%d", &n); f[1] = f[2] = 1; if(n == 1 || n == 2) { puts("1"); return 0; } for(int i = 3; i <= n; i++) { f[i] = (f[i - 1] + f[i - 2]) % 10007; } printf("%d",f[n]); return 0; }
acos(-1) 圆周率
//a ber #include5、十六进制转八进制using namespace std; const double pi = acos(-1); double x; signed main() { scanf("%lf",&x); printf("%.7f",pi*x*x); return 0; }
将十六进制转化成二进制,再将二进制转化成八进制,注意前导0处理
#include6、十六进制转十进制using namespace std; string s; string a[16] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111" }; map ok; signed main() { ok["000"] = "0"; ok["001"] = "1"; ok["010"] = "2"; ok["011"] = "3"; ok["100"] = "4"; ok["101"] = "5"; ok["110"] = "6"; ok["111"] = "7"; int _; scanf("%d", &_); for(int T = 0; T < _; T++) { cin >> s; int n = s.size(); string b; for(int i = 0; i < n; i++) { s[i] > '9' ? b += a[s[i] - 'A' + 10] : b += a[s[i] - '0']; } int nn = b.size(); //处理位数不足三的倍数的情况 if(nn % 3 == 1) { b = "00" + b; } if(nn % 3 == 2) { b = "0" + b; } int f = 0; for(int j = 0; j < nn; j += 3) { string tmp = b.substr(j, 3); string t = ok[tmp]; //前导0的处理 if(j == 0 && t == "0") { f = 1; continue; } if(f == 1 && j == 3 && t == "0") { continue; } cout << t; } cout << "n"; } return 0; }
#include7、十进制转十六进制#define int long long using namespace std; string s; int fp(int a, int b) { int ok = 1; while(b) { if(b & 1) ok *= a; a *= a; b >>= 1; } return ok; } signed main() { int ok = 0; cin >> s; reverse(s.begin(), s.end()); for(int _ = 0; _ < s.size(); _++) { s[_] > '9' ? ok = ok + (s[_] - 'A' + 10) * fp(16, _) : ok = ok + (s[_] - '0') * fp(16, _); } printf("%lld", ok); return 0; }
除k取余法emmm。。。
#includeusing namespace std; int a; vector ok; signed main() { int a; scanf("%d", &a); int tmp; if(a == 0) { puts("0"); return 0; } while(a) { tmp = a % 16; tmp > 9 ? ok.push_back(char('A' + tmp - 10)) : ok.push_back(char('0' + tmp)); a /= 16; } for(int _ = ok.size() - 1; _ >= 0; _--) { printf("%c", ok[_]); } return 0; }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)