标签:style int break else sum ble for image ges
输入格式:一个整型,然后循环输入一个字符加一个整型。
思考:首先用scanf_s()函数输入整型。然后一个大循环,用scanf_s()函数同时输入字符和整型。第一个scanf_s()函数后,后面还要输入一个字符,为了消除第一个scanf_s()函数缓冲区里面的字符对后面字符输入的影响,第一个scanf_s()函数要多加一个%c,&d。同样,在大循环里面的第二个scanf_s()函数,也要多加一个%c,&d。目的是一样的。
#include <stdio.h> #include <string.h> char a[27], b[27]; int na[27], nb[27]; int main() { a[0] = ‘a‘; na[0] = 1; for (int i = 1; i<26; i++) { a[i] = a[i - 1] + 1; na[i] = na[i - 1] + 1; } b[0] = ‘A‘; nb[0] = 1; for (int i = 1; i<26; i++) { b[i] = b[i - 1] + 1; nb[i] = i + 1; } int T; char d; scanf("%d%c", &T, &d); for (int i = 0; i<T; i++) { char ch; int num; int sum = 0; scanf("%c%d%c", &ch, &num,&d); if (ch >= ‘a‘&&ch <= ‘z‘) { for (int i = 0; i<26; i++) { if (ch == a[i]) { sum = sum + na[i]; break; } } sum = -sum + num; printf("%d\n", sum); } else if (ch >= ‘A‘&&ch <= ‘Z‘) { for (int i = 0; i<26; i++) { if (b[i] == ch) { sum = sum + nb[i]; break; } } sum = sum + num; printf("%d\n", sum); } } }
标签:style int break else sum ble for image ges
原文地址:http://www.cnblogs.com/Strugglinggirl/p/5988901.html