【十二月】第三次课堂练习
作者:互联网
P1914
#include<iostream> #include<string.h> using namespace std; int main() { char s[51]; int n; scanf("%d",&n); scanf("%s",s); for(int i=0;i<strlen(s);i++) { for(int j=1;j<=n;j++) { s[i]++; if(s[i]>'z') s[i]='a'; } } printf("%s",s); return 0; }View Code
P1957
#include<stdio.h> #include<stdlib.h> #include<string.h> int len(int a) { int c = a / 10; int num = 1; while(c != 0) { c = c / 10; num ++; } return num; } void fun(char data1[],char data2[],char symble) { int len1 = strlen(data1); int len2 = strlen(data2); int sum1 = 0,sum2 = 0;//计算两个字符串代表的数据 for(int j = 0; j < len1; j ++) { sum1 = data1[j] - '0' + sum1 * 10; } for(int j = 0; j < len2; j ++) { sum2 = data2[j] - '0' + sum2 * 10; } int sum = 0; if(symble == 'a') { sum = sum1 + sum2; printf("%s+%s=%d\n",data1,data2,sum); if(sum < 0) printf("%d\n",len1 + len2 + 3 + len(sum)); else printf("%d\n",len1 + len2 + 2 + len(sum)); } if(symble == 'b') { sum = sum1 - sum2; printf("%s-%s=%d\n",data1,data2,sum); if(sum >= 0) printf("%d\n",len1 + len2 + 2 + len(sum)); else printf("%d\n",len1 + len2 + 3 + len(sum)); } if(symble == 'c') { sum = sum1 * sum2; printf("%s*%s=%d\n",data1,data2,sum); if(sum >= 0) printf("%d\n",len1 + len2 + 2 + len(sum)); else printf("%d\n",len1 + len2 + 3 + len(sum)); } } int main() { char data1[1000]; char data2[1000]; char symble; int n; scanf("%d",&n); for(int i = 0; i < n; i ++) { scanf("%s",data1);//接受第一个字符串 if(data1[0] == 'a' || data1[0] == 'b' || data1[0] == 'c')//为三数据输入 { symble = data1[0]; scanf("%s%s",data1,data2); fun(data1,data2,symble); } else { scanf("%s",data2); fun(data1,data2,symble); } } return 0; }View Code
标签:课堂练习,十二月,int,sum,printf,data2,data1,symble,第三次 来源: https://www.cnblogs.com/orange-/p/15704394.html