1064 Financial Management
一开始居然把12写成n
#includeusing namespace std; int main() { int n = 12; double sum = 0; double salary; while (n--) { cin >> salary; sum += salary; } printf("%.2lfn",sum/12); return 0; }
1062 Text Reverse
就是输入一行字符串,然后翻转这一个行中被空格分隔的单词。最后再把处理过的该行字符串输出即可。
先用begin变量标记一个起点,然后遍历一遍字符串,遇到空格就保存空格前面一位到begin位置(顺序不能错)的所有字符,然后再保存一个空格,并且更新begin的位置。
#include#include #include using namespace std; int main() { int t; cin>>t; getchar(); while(t--) { string a,ans; getline(cin,a); int begin = 0,len = a.size() - 1; ans = ""; for(int i = 0;i <= len;i++) { //判断最后一位是否为空格还是字符 if(i == len&&a[i] != ' ') { for(int j = i;j >= begin;j--) ans += a[j]; } else if(a[i] == ' '||(i == len&&a[i] == ' ')) { for(int j = i - 1;j >= begin;j--) ans += a[j]; ans += ' '; begin = i + 1;//更新起点 } } cout< #include#include int main() { int n; char s[1001]; int i, j; while (scanf("%d",&n)!=EOF) { getchar(); while (n--) { gets(s); int len = strlen(s); int flag = 0; for (i = 0; i < len; ++i) { if (s[i] == ' ') { for (j = i - 1; j >= flag; --j) { printf("%c",s[j]); } printf(" "); flag = i + 1; } } for (j = i - 1; j >= flag; --j) { printf("%c",s[j]); } printf("n"); } } return 0; } 2104 hide handkerchief
n个人围成一个圈玩找手帕游戏,手帕藏在某一个人的箱子里,Haha来找,每一次他都会跳过m-1个人。问Haha是不是一定能找到手帕。
其实就是看盒子数和步数,走一圈能不能会到原点,发现规律这二个数是互质就是最大公约数为1#includeusing namespace std; int gcd(int n,int m) { if (n < m) { int temp = m; m = n; n = temp; } while (m != 0) { int num = n % m; n = m; m = num; } return n; } int main() { int n, m; while (cin >> n >> m,n!=-1,m!=-1) { if (gcd(n,m) == 1) { cout << "YES" << endl; } else { cout << "POOR Haha" << endl; } } return 0; } 2734 Quicksum
#includeusing namespace std; int main() { string input_str; while (getline(cin,input_str),input_str[0]!='#') { int length = input_str.size(); int sum = 0; for (int i = 0; i < length; ++i) { if (input_str[i] == ' ') { continue; } sum += (i + 1) * (input_str[i] - 64);//(input_str[i]-'A'+1) } cout << sum << endl; } return 0; } 1170 Balloon Comes!
#includeint main(){ int T; int A,B; char C; float result; scanf("%d",&T); getchar(); while(T--){ scanf("%c%d%d",&C,&A,&B); getchar(); switch(C){ case '+':result = A+B;break; case '-':result = A-B;break; case '*':result = A*B;break; case '/':result = (double)A/B;break; } if(C=='/' && A%B!=0){ printf("%.2fn",result); }else{ printf("%dn",(int)result); } } return 0; } 1197 Specialized Four-Digit Numbers
#includeusing namespace std; int tar(int n,int num) { int sum = 0; while (num >= n) { sum += num % n; num /= n; } return sum + num; } void judge(int num) { int shi, shier , shiliu; shi = tar(10,num); shier = tar(12,num); shiliu = tar(16,num); if (shi == shier && shi == shiliu) { cout << num << endl; } return; } int main() { for (int i = 2992; i <= 9999; ++i) { judge(i); } return 0; } #includeusing namespace std; int main() { for (int i = 2992; i <= 9999; ++i) { int sum10 = 0, sum12 = 0, sum16 = 0; int r = i; while (r) { sum10 += r % 10; r /= 10; } r = i; while (r) { sum12 += r % 12; r /= 12; } r = i; while (r) { sum16 += r % 16; r /= 16; } if (sum10 == sum12 && sum10 == sum16) { cout << i << endl; } } return 0; } 2629 Identity Card
int n; string input_str,place; cin>>n; for(int i=0; i>input_str; if(input_str.substr(0,2)=="33") place="Zhejiang"; else if(input_str.substr(0,2)=="11") place="Beijing"; else if(input_str.substr(0,2)=="71") place="Taiwan"; else if(input_str.substr(0,2)=="81") place="Hong Kong"; else if(input_str.substr(0,2)=="82") place="Macao"; else if(input_str.substr(0,2)=="54") place="Tibet"; else if(input_str.substr(0,2)=="21") place="Liaoning"; else if(input_str.substr(0,2)=="31") place="Shanghai"; cout <<"He/She is from"<<" "<< place << ",and his/her birthday is on"<<" "< #includeusing namespace std; #include 欢迎分享,转载请注明来源:内存溢出
评论列表(0条)